
Purpose of Structural Models • Class diagrams represent • Generic Categories (classes) of things (objects) • Define relationships among Generic Categories (classes) of things (objects)
Classes • Generic type of thing • Objects are the individual things • Classes are templates for creating instances or objects • Concrete • Abstract • Typical examples: • Application domain, user interface, data structure, file structure, operating environment, document, and multimedia classes
Attributes • Facts related to a type of thing • Attributes of a class • Class – Car Attribute may include: Make, Model, Engine size, etc • Only attributes important to the task should be included
Operations • Behavior types of things do • Class – Car, Operation – accelerate(), break(), etc • Action that instances/objects can take – defined by the class • Focus on relevant problem-specific operations (at this point) • Quick Exercise – in 1 minute
Exercise 1 - Classes • A Cinema shows films. Each film has a title, a producer, a director, a length, certificate and a genre. Patrons watch films at the cinema. Patrons are either adults or children and have a name and an age. To see a film a patron has to buy a ticket. A ticket has a price, a time and is for a film.
Class Diagram • Mechanism for visualising classes • Became truly central within all object oriented methods • A Class Diagram shows • Classes • Attributes • Operations • Relationships • Which are consistent over time • Shows the structure of things and ideas in a system
Basic Diagram • Identify Classes • Draw a rectangle for each class • Name it
Add attributes and operations • For each class identified • Identify attributes • Facts associated with classes • Identify operations/methods • Actions objects of the classes do • Re-factor • Are the attributes in the right class? • Are the operations in the right class?
Simple Class Diagram Class Attributes Operations
Relationships • Some Classes can be related • Relationships have difference types • Generalization / Specialization • Aggregation • Composition • Association
Relationships • Classes do not exist in isolation • It is important to consider how they • Interact • Relate • Tend to be VERBS • Five principal types of relationships
Type One - Dependency • Where one class must know about another • Example: • Prospective student knows of a course • Not commonly used • Used more commonly in design / implementation • Java – import javax.swing.*; Car Wheel
Type Two - Association • Classes associated with / related to one another • Example • Student studies a course • Very Commonly used • “Default” type of relationship studies► Student Course
Type Three - Aggregation • Classes made up of other classes • “Part of” relationship • Objects of classes that can exist in their own right • Example • Student is a member of a seminar group memberOf ► Seminar Student
Type Four - Composition • Class is an integral part of another • “Integral part of” relationship • Object of classes that cannot exist without the other • Example: • Seminar is delivered for a Module deliveredFor ► Seminar Module
PartTimeStudent Student Type Five Inheritance • Specialisation / generalisation between two classes • Example • Part Time Student is a type of Student
Association Classes • Sometimes the way in which objects of a class are associated is just as important as the objects of a class themselves • Consider the association between Student and Module. Where should our system record the student’s marks on for each student on each module? 1..* is taking 6 Student Module association class is taking mark : Integer
Constraints • a constraint is a condition that has to be satisfied • Use with care • Too much text on a diagram • Can be over used
Recursive Association- is allowed, and can be useful ! • an employee, as a manager, may manage other employees; each employee may be managed by another employee 0..* employee manages 0..1
Class v. Object Diagram Staff • full symbol for an object is a box with 3 compartments • class name • attributes • operations staffName staffID staffstartdate staffdept an instance symbol shows both instance and class name underlined with a colon to separate AkhtarAli:Staff staffName=Akhtar Ali staffID=313 staffstartdate=140800 staffdept=SDE in an instance symbol, both attribute names and values are given
ที่มา • IS0514, Business Systems Development Tools and Techniques, Northumbria University: Dr. M. Akhtar Ali