Professional Documents
Culture Documents
BITS Pilani
Pilani Campus
BITS Pilani
Pilani Campus
Lecture Session-8
22- 08-13
2
BITS Pilani
Pilani Campus
UML Class
A class is a template for actual, in-memory, instances
Operations
UML Class
Class Attributes
Attributes are the instance and class data members
Class data members (underlined) are shared between all instances (objects) of a given class Data types shown after ":" Attribute compartment
Class Operations
Operations are the class methods with their argument and return types
Class methods (underlined) have only access to class data members, no need for a class instance (object)
visibility name : type Operations compartment
Visibility
public (+) external objects can access the member private (-) only internal methods can access the member protected (#) only internal methods, or methods of specialized objects can access the member
Association
Represent relationship between instances of classes Student enrolls in a course Courses have students Courses have exams Etc. Association has two ends Role names (e.g. enrolls) Multiplicity (e.g. One course can have many students) Navigability (unidirectional, bidirectional)
Description
Syntax
a relationship between two or more classifiers that involves connections among their instances. A special form of association that aggregation specifies a whole-part relationship between the aggregate (whole) and the component part. generalization a taxonomic relationship between a more general and a more specific element. a relationship between two modeling dependency elements, in which a change to one modeling element (the independent element) will affect the other modeling element (the dependent element).
BITS Pilani, Pilani Campus
Multiplicity (Cardinality)
These symbols indicate the number of instances of one class linked to one instance of the other class.
26-Oct-13
13
Aggregation
Container Class Class C AGGREGATION
Aggregation:
Class E1
Class E2
expresses a relationship among instances of related classes. It is a specific kind of Container-Containee relationship. express a more informal relationship than composition expresses.
Computer
Aggregation is appropriate when Container and Containees have no special access privileges to each other.
Motherboard
Composition
Association
Whole Class Class W
Composition
Class P1 Class P2
Also models the partwhole relationship but, in addition, Every part may belong to only one whole, and If the whole is deleted, so are the parts
Example:
A number of different chess boards: Each square belongs to only one board. If a chess board is thrown away, all 64 squares on that board go as well.
Aggregation Association
We can model objects that contain other objects by way of special associations called aggregations and compositions. An aggregation specifies a whole-part relationship between an aggregate (a whole) and a constituent part, where the part can exist independently from the aggregate. Aggregations are denoted by a hollow-diamond adornment on the association. Engine
Car
Wheel
Composition Association
A composition indicates a strong ownership and coincident lifetime of parts by the whole (i.e., they live and die as a whole). Compositions are denoted by a filled-diamond adornment on the association. Scrollbar
Titlebar Menu
Window
1 .. *
Generalization
Generalization is another name for inheritance or an "is-a" relationship.
18
Generalization Relationship
UML permits a class to inherit from multiple superclasses, although some programming languages (e.g., Java) do not permit multiple inheritance. Student Employee
TeachingAssistant
Dependency
A dependency exists between two elements if changes to the definition of one element may cause changes to the other The dependency relationship is useful to depict nonattribute visibility between classes. Parameters Global or local visibility A dashed directed line Many dependencies have already special UML notations superclass interface implementation attributes as associations.
BITS Pilani, Pilani Campus
Dependency
A dependency indicates a semantic relationship between two or more elements. Indicating one element has knowledge of another element
Circle Point
Move(p:Point)
Dependency Relationship
Change in specification of one class can change the other class. This can happen when one class is using another class. The dependency from CourseSchedule to Course exists because Course is used in both the add and remove operations of CourseSchedule. CourseSchedule Course add(c : Course) remove(c : Course)
Association Relationship
Associations can also be objects themselves, called link classes or an association classes. Registration modelNumber serialNumber warrentyCode
Product
Warranty
Association Class
which is both an association and a class is an association class
Qualified Associations
A qualified association associates two objects using a qualifier to select objects at the other end of the association. A qualifier is an attribute or set of attributes which has a unique value for each object in the class.
Qualified composition
In fact we can combine the qualified association notation with the other adornments on associations For example, we can add back the information that this particular association is a composition
Constraints
A constraint is a condition that has to be satisfied by any correct implementation of a design The formal constrains can be written in OCL, the Object Constraint Language (developed by IBM) OCL is intended to be
Formal, so that constraints written in it are unambiguous Easy to use, so that every developer can write constraints in it
Interface Services
Interfaces do not get instantiated. <<interface>> ControlPanel
getChoices : Choice[] makeChoice (c : Choice) getSelection : Selection No attributes or state. Rather, they specify the services offered by a related class. Same notation as class except: has word interface All methods are public
Realization- Interface
A realization relationship indicates that one class implements a behavior specified by another class (an interface or protocol). Interface is a set of operation the class carries out It is rendered by a dashed line with a hollow triangle towards the specified.
Keyboard
brandName numOfKeys ctl() pageDown() <<interface>> TypeWriter Keyboard
OR
keyStroke()
brandName numOfKeys
ctl() pageDown() TypeWriter
Association - Self
A Company has Employees. A single manager is responsible for up to 10 workers.
1 Employee
Responsible for
manager
0..10
worker
Relationships
26-Oct-13
31
Singleton Classes
Attributes can be shown visually for class associations, or in text : for basic data types only
Collection Attributes
Visibility marks include + (public) and (private). Operations are usually assumed public if no visibility is shown. A UML method is the implementation of an operation, it may be illustrated using: An interaction diagram A class diagram
BITS Pilani, Pilani Campus
Sale
classes identified in the interaction diagrams are declared in the class diagrams
makePayment() ...
Parameters
Register method // pseudo-code or a specific language is OK public void enterItem( id, qty ) { ProductDescription desc = catalog.getProductDescription(id); sale.makeLineItem(desc, qty); } ... endSale() enterItem(id, qty) makeNewSale() makePayment(cashTendered)
Dependency
A dependency exists between two elements if changes to the definition of one element may cause changes to the other The dependency relationship is useful to depict nonattribute visibility between classes. Parameters Global or local visibility A dashed directed line Many dependencies have already special UML notations superclass interface implementation attributes as associations.
BITS Pilani, Pilani Campus
Class Diagram
1 ProductCatalog 1 Contains 1..* StockItem barcode description ItemSold Contained-in brand Described-by qtySold paidPrice : Currency 1..* 1 retailPrice : Currency 1 qtyInStock sell() buy() 1 Sale checkOutNo date&Time Captured-on 1 1 1 POST Used-by 1 Houses 1..* Belongs-to 1 Store
calculateCost() Records-sales-on printDocket() 1 1 1 addItem() cancelItem() Cashier Initiated-by (from Use Case View) 1
Payment amountDue
Paid-by
accept() cancel()
CreditPayment
EFTPOSPayment cashOut
Conclusions
Class diagrams Attributes and operations of classes Association Composition Dependency Aggregation Generalization