Topics Covered Today Unit 1. 2 Designing Classes 1. 2. 1 UML Class diagrams 1.2.2 Relationships between Classes 1.2.3 Common Class structures 1.2.4 UML with eclipse
2 Topics Covered Today • Unit 1.2 Designing Classes – 1.2.1 UML Class Diagrams – 1.2.2 Relationships Between Classes – 1.2.3 Common Class Structures – 1.2.4 UML with Eclipse
UML Introduction Programming is like building a house. An architect creates a design, and a builder uses appropriate tools to carry out the design The builder does not proceed without a blueprint from the architect Software developers also need a blueprint to create complex systems The UML is a toolbox of graphical notations used to produce the blueprint a graphical l depiction of the software design UML, Unified modeling language
3 UML Introduction • Programming is like building a house. An architect creates a design, and a builder uses appropriate tools to carry out the design. The builder does not proceed without a blueprint from the architect. • Software developers also need a blueprint to create complex systems. • The UML is a toolbox of graphical notations used to produce the blueprint -- a graphical depiction of the software design • UML, Unified Modeling Language
Unified Modelling Language (UML) A graph ohio cal language for Visualising Specifying Constructin g Documenting Object-oriented software systems ·OMG( Object management Group国际对象管理 组织) is responsible for UML standard
4 Unified Modelling Language (UML) • A graphical language for – Visualising – Specifying – Constructing – Documenting • Object-oriented software systems • OMG (Object Management Group国际对象管理 组织) is responsible for UML standard
UML UML is not a method it does not outline a procedure for designing software; It is a modeling language that captures the design graphically Whatever process you use you can use uml to record the results of your anal ysis and design decisions
5 UML • UML is not a method. It does not outline a procedure for designing software; it is a modeling language that captures the design graphically. • Whatever process you use, you can use UML to record the results of your analysis and design decisions
UML The main reason to use uml notation is communication To discuss design with someone both need to understand the modeling language, not the process used to come up with the design Human language is imprecise Code is too detailed
6 UML • The main reason to use UML notation is communication. – To discuss design with someone, both need to understand the modeling language, not the process used to come up with the design. – Human language is imprecise – Code is too detailed
UML Diagrams Use case diagram(用例图) Class diagram(类图 Behavior diagrams(行为图) Statechart diagram(状态图) Activity diagram(活动图) Interaction diagrams(交互图 Sequence diagram(顺序图) Collaboration diagram(协作图) Implementation diagrams(实现图) Component diagram(组件图) Deployment diagram(部署图)
7 UML Diagrams • Use case diagram (用例图) • Class diagram (类图) • Behavior diagrams (行为图) – Statechart diagram (状态图) – Activity diagram (活动图) – Interaction diagrams (交互图) • Sequence diagram (顺序图) • Collaboration diagram (协作图) • Implementation diagrams (实现图) – Component diagram (组件图) – Deployment diagram (部署图)
Class notation a class is represented by a rectangle with three compartments The first compartment contains the name of the class the second compartment describes the attributes of the class and the third compartment describes the methods of the class
8 Class Notation • A class is represented by a rectangle with three compartments. – The first compartment contains the name of the class; – the second compartment describes the attributes of the class; – and the third compartment describes the methods of the class
UML Class Diagram NameClass name attribute: Type attribute attribute2: Type I+method1(param 1: lype, param2: Type) method +method2 (paramI: Ty pe, param2 pe pe pI rivate ·+ public protected
9 UML Class Diagram NameClass -attribute1 : Type -attribute2 : Type +method1(param1 : Type, param2 : Type) : Type +method2(param1 : Type, param2 : Type) : Type name attribute method • - private • + public • # protected
Employee class This class contains three private attributes name hourly Wage hour Worked It also contains the following public methods Methods to access the values of the attributes getName, getHourly Wage, and getHours Worked Methods to modify the values of the attributes setName set hourly Wage, and setHours Worked a method to obtain the employee's earnings getEarnings
10 Employee Class • This class contains three private attributes: – name – hourlyWage – hourWorked • It also contains the following public methods: – Methods to access the values of the attributes: • getName, getHourlyWage, and getHoursWorked – Methods to modify the values of the attributes: • setName, setHourlyWage, and setHoursWorked – A method to obtain the employee's earnings: • getEarnings
Representation of employee employee name String hourly Wage: Double -hours Worked double +getName(: String +get Hourly Wage(: Double +getHours Worked: Double +setName(newName: String +sethourly Wage(newHourly Wage: Double) +sethours Worked(new Hours Worked Double) +get Earnings(: Double
11 Representation of Employee Employee -name : String -hourlyWage : Double -hoursWorked : Double +getName() : String +getHourlyWage() : Double +getHoursWorked() : Double +setName(newName : String) +setHourlyWage(newHourlyWage : Double) +setHoursWorked(newHoursWorked : Double) +getEarnings() : Double