Aggregations and Identity · Generalization • Generalization is a relationship between a general...

25
Aggregations and Identity

Transcript of Aggregations and Identity · Generalization • Generalization is a relationship between a general...

Page 1: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Aggregations and Identity

Page 2: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Aggregation

• Aggregation represents a relation “contains”,“is a part of”, “whole-part” relation.

• Indicated by a line adorned on the “whole” bya hollow diamond– Along with name of relationship and– Cardinality.

2/9/2016 2

• Aggregation represents a relation “contains”,“is a part of”, “whole-part” relation.

• Indicated by a line adorned on the “whole” bya hollow diamond– Along with name of relationship and– Cardinality.

Page 3: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Aggregation: Example

containsLeague Team

*

Membership aggregation: A league is made up ofMany teams.

2/9/2016 3

Membership aggregation: A league is made up ofMany teams.

made ofAuto

wheel

engine

4

1

part*

Strong aggregation.

Page 4: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Generalization

• Generalization is a relationship between a generaland a specific class.

• The specific class called the subclass inherits fromthe general class, called the superclass.

• Public and protected properties (attributes) andbehaviors (operations) are inherited.

• Design representation “inheritance” OO concept.

2/9/2016 4

• Generalization is a relationship between a generaland a specific class.

• The specific class called the subclass inherits fromthe general class, called the superclass.

• Public and protected properties (attributes) andbehaviors (operations) are inherited.

• Design representation “inheritance” OO concept.

Page 5: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Generalization: Symbol

• It represents “is a” relationship among classesand objects.

• Represented by a line with an hollow arrowhead pointing to the superclass at thesuperclass end.

2/9/2016 5

• It represents “is a” relationship among classesand objects.

• Represented by a line with an hollow arrowhead pointing to the superclass at thesuperclass end.

Page 6: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Generalization: Example

Vehicle

2/9/2016 6

Car Boat Truck

Page 7: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Combined Example

VehiclePersondrives

0..*

2/9/2016 7

Car Boat Truck

Page 8: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Discovering ClassesLibrary Management System (LMS)

RESPONSIBILITIES

1. Borrow item2. Reserve item3. Return item4. Remove reservation5. Add borrower6. Update or remove borrower7. Add title (book or magazine)8. Update or remove title9. Add item10. Update or remove item11. Store loan details

COLLABORATIONS

Item

ReservationBorrower

TitleBook TitleMagazine Title

Loan (Transaction)

Database2/9/2016 8

RESPONSIBILITIES

1. Borrow item2. Reserve item3. Return item4. Remove reservation5. Add borrower6. Update or remove borrower7. Add title (book or magazine)8. Update or remove title9. Add item10. Update or remove item11. Store loan details

COLLABORATIONS

Item

ReservationBorrower

TitleBook TitleMagazine Title

Loan (Transaction)

Database

Page 9: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

CRC Cards

• LMS• (Librarian)• Borrower• Title: Book Title, Magazine Title• Item• Reservation• Transaction (Loan)• Database for storage

2/9/2016 9

• LMS• (Librarian)• Borrower• Title: Book Title, Magazine Title• Item• Reservation• Transaction (Loan)• Database for storage

Page 10: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Static Analysis: Initial ClassDiagram

Objects of theseclasses are allpersistent data (ina Database)

BookTitle MagazineTitle0..1LoanTransaction

0..*

Borrower

0..* 0..*

Item

0..1

0..*

Reservation

0..*

0..*

Title

0..*

0..*

2/9/2016 10

Objects of theseclasses are allpersistent data (ina Database)

BookTitle MagazineTitle0..1LoanTransaction

0..*

Borrower

0..* 0..*

Item

0..1

0..*

Reservation

0..*

0..*

Title

0..*

0..*

Page 11: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Dynamic Analysis

• “Borrow Item” use case using SequenceDiagram

• “Add Title” use case using Collaborationdiagram

• “Add Item” using Activity diagram• “Reservation” state diagram

2/9/2016 11

• “Borrow Item” use case using SequenceDiagram

• “Add Title” use case using Collaborationdiagram

• “Add Item” using Activity diagram• “Reservation” state diagram

Page 12: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Borrow Item: Sequence Diagram

: BorrowerBison : LMS : Borrower

1: findTitle ( )

: Title : LoanTransaction

: Item

2: find ( )

3: findItem ( )4: searchItem ( )

5: identifyBorrower ( )6: findBorrower ( )

7: createLoanTrans ( )

2/9/2016 12

: BorrowerBison : LMS : Borrower

1: findTitle ( )

: Title : LoanTransaction

: Item

2: find ( )

3: findItem ( )4: searchItem ( )

5: identifyBorrower ( )6: findBorrower ( )

7: createLoanTrans ( )

Page 13: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Add Title: Collaboration Diagram

name, ISBN

: Librarian

: Title

Assuming thatadd title impliesadding an item

: Item

1: create ( )

id

2: setItem ( )ObjId,id

3: addItem ( )

Objid

DB : DB

4: storeTitle ( )

titleObj

5: storeItem ( )

itemObj

2/9/2016 13

name, ISBN

: Librarian

: Title

Assuming thatadd title impliesadding an item

: Item

1: create ( )

id

2: setItem ( )ObjId,id

3: addItem ( )

Objid

DB : DB

4: storeTitle ( )

titleObj

5: storeItem ( )

itemObj

Page 14: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Add Item: Activity Diagram

c r e a t e I t e m

s e t I t e m

a d d T o T i t l e u p d a t e D a t a b a s e

Title Item Database

2/9/2016 14

c r e a t e I t e m

s e t I t e m

a d d T o T i t l e u p d a t e D a t a b a s e

Page 15: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Component Diagram

GUI Package+ Lend Window+ Return Window+ Reservation Window+ Maintenance Window

Business Package+ Item+ Loan+ Title+ Borrower information+ Book Title+ Reservation+ Magazine Title

2/9/2016 15

GUI Package+ Lend Window+ Return Window+ Reservation Window+ Maintenance Window

Business Package+ Item+ Loan+ Title+ Borrower information+ Book Title+ Reservation+ Magazine Title

Page 16: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Analysis, DesignImplementation/programming

• What is the deliverable at the end of theanalysis and design phase?

• One or more class diagrams showing theclasses and the relationships that define theOOD.

• On to OOP: Object-oriented programming.

• What is the deliverable at the end of theanalysis and design phase?

• One or more class diagrams showing theclasses and the relationships that define theOOD.

• On to OOP: Object-oriented programming.

2/9/2016 16

Page 17: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Problem Solving Using Java

OO Design and Progamming in Java

Identify classes needed Write anapplicationclass

Write anappletclass

2/9/2016 17

Identify classes needed

Reuse APIclasses

Reuseyour classes

Design newclasses

Write anapplicationclass

Write anappletclass

Create and use objects

Page 18: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Instantiation : Examples

• class FordCar ---- defines a class name FordCar• FordCar windstar; ---- defines a Object reference windStar• windstar = new FordCar(); ---- instantiates a windstar Object

• class HousePlan1 { color….• HousePlan1 blueHouse;• blueHouse = new HousePlan1(BLUE);• HousePlan1 greenHouse = new HousePlan1(GREEN);

2/9/2016 18

• class FordCar ---- defines a class name FordCar• FordCar windstar; ---- defines a Object reference windStar• windstar = new FordCar(); ---- instantiates a windstar Object

• class HousePlan1 { color….• HousePlan1 blueHouse;• blueHouse = new HousePlan1(BLUE);• HousePlan1 greenHouse = new HousePlan1(GREEN);

Page 19: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Operator new and “dot”

• new operator creates a object and returns areference to that object.

• After an object has been instantiated, you canuse dot operator to access its methods anddata declarations (if you have accesspermissions).

• EX: redRose.bloom(); greenHouse.color

2/9/2016 19

• new operator creates a object and returns areference to that object.

• After an object has been instantiated, you canuse dot operator to access its methods anddata declarations (if you have accesspermissions).

• EX: redRose.bloom(); greenHouse.color

Page 20: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Elements of a Class

class

header methods data declarations (variables,constants)

2/9/2016 20

headerbody

variables,constants

statementsmodifiers,type, name

parameters

selection repetition

assignment

others

Page 21: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Class Structure

class

2/9/2016 21

variablesconstants

methods

Page 22: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Defining Classes• Syntax:• class class_name {• data-declarations• constructors• methods }• Constructors are special methods used for

instantiating (or creating) objects from a class.• Data declarations are implemented using variable

and constant declarations.

2/9/2016 22

• Syntax:• class class_name {• data-declarations• constructors• methods }• Constructors are special methods used for

instantiating (or creating) objects from a class.• Data declarations are implemented using variable

and constant declarations.

Page 23: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Naming Convention

• Constants: All characters in uppercase, words in theidentifier separated by underscore: EX: MAX_NUM

• Variables, objects, methods: First word all lowercase,subsequent words start with uppercase. EX: nextInt,myPen, readInt()

• Classes: Start with an uppercase letter. EX: Tree, Car,System , Math

• Packages: are formed by set of related classes andpackages.

2/9/2016 23

• Constants: All characters in uppercase, words in theidentifier separated by underscore: EX: MAX_NUM

• Variables, objects, methods: First word all lowercase,subsequent words start with uppercase. EX: nextInt,myPen, readInt()

• Classes: Start with an uppercase letter. EX: Tree, Car,System , Math

• Packages: are formed by set of related classes andpackages.

Page 24: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

A complete example

• Problem Statement: You have been hired toassist in an secret encryption project. In thisproject each message (string) sent out isattached to a randomly generated secret code(integer) between 1 and 999. Design anddevelop an application program in Java tocarry out this project.

2/9/2016 24

• Problem Statement: You have been hired toassist in an secret encryption project. In thisproject each message (string) sent out isattached to a randomly generated secret code(integer) between 1 and 999. Design anddevelop an application program in Java tocarry out this project.

Page 25: Aggregations and Identity · Generalization • Generalization is a relationship between a general and a specific class. • The specific class called the subclass inherits from the

Identify Objects

• There are two central objects:– Message– Secret code

• Is there any class predefined in JAVA API thatcan be associated with these objects? Yes ,– “string” of java.lang and “Random” of java.util

2/9/2016 25

• There are two central objects:– Message– Secret code

• Is there any class predefined in JAVA API thatcan be associated with these objects? Yes ,– “string” of java.lang and “Random” of java.util