- Multiplicity UML and Classes, Objects and Relationships [ 2] Defining Domain Models Using Class Diagrams A can take many Courses and many s can be enrolled in one Course. Alice: takes * * 254: Course Course Jill: 253: Course 2 Notes One class can be relate to another in a One-to-one One-to-many One-to-one or more One-to-zero or one One-to-a bounded interval (one-to-two through twenty) One-to-exactly n One-to-a set of choices (one-to-five or eight) Notes Multiplicity can be expressed as, Exactly one - Zero or one - 0.. Many - 0..* or * One or more - Exact Number - e.g. 3..4 or 6 Or a complex relationship e.g. 0.., 3..4, 6..* would mean any number of objects other than 2 or 5 3 4 - Self - Self An association that connects a class to itself is called a self association. A Company has Employees. A single manager is responsible for up to 0 workers. Responsible for manager 0..0 Employee worker 5 6
- Multiplicity Team Member 0 A cricket team has players. One of them is the captain. A player can play only for one Team. The captain leads the team members. Player Captain Captain 0.. member of Team Leads 7 8 (Inheritance) (Inheritance) e.g. Child class is a special case of the parent class SuperClass Graphic SubClass SubClass2 9 0 Inheritance - Implementation Abstract Class public class { Shape public class Graphic extends { Rectangle 2
Abstract Methods (Operations) Shape Abstract class and method Implementation public abstract class Shape { public abstract ; //declare without implementation Rectangle public class { public {... 3 4 - Interface Interface is a set of operation the class Keyboard brandname numofkeys ctl() pagedown() carries out <<interface>> TypeWriter keystroke() OR Keyboard brandname numofkeys ctl() pagedown() TypeWriter 5 6 - Implementation public interface TypeWriter { void keystroke() public class KeyBoard implements TypeWriter { public void keystroke(){ 7 8
cont Change in specification of one class can change the other class. This can happen when one class is using another class. Move(p:Point) Point relationship can be used to show relationships between classes and objects. < <instanceof> > < < instanceof> > circlea: circleb: 9 20 Class Diagrams The UML class diagram consists of several Classes, connected with Relationships. 2 Draw a class diagram for a information modeling system for a school. has one or more s. offers one or more Subjects. A particular subject will be offered by only one department. has instructors and instructors can work for one or more departments. can enrol in upto 5 subjects in a. Instructors can teach upto 3 subjects. The same subject can be taught by different instructors. s can be enrolled in more than one school. 22 has one or more s. has offers one or more Subjects. A particular subject will be offered by only one department. has Instructors and instructors can work for one or more departments. Instructor assigned to can enrol in upto 5 Subjects. offers Subject takes * 0..5 Subject 23 24
Instructors can teach up to 3 subjects. The same subject can be taught by different instructors. s can be enrolled in more than one school. Instructor teaches..3 Subjects * member 25 26 Class Diagram Example Object Diagram * member has offeres assignedto Object Diagram shows the relationship between objects. Unlike classes objects have a state. * attends teaches Subject Instructor *..5..3 27 28 Object Diagram - Example c: Company d: name= Sales d2: name= R&D manager p: Persont name= John employee p2: Person name= David 29