550 likes | 711 Views
COP 3503 FALL 2012 Shayan Javed Lecture 9. Programming Fundamentals using Java. UML Diagrams. UML. U nified M odeling L anguage. UML. U nified M odeling L anguage Goal: Common language for creating models of Object-Oriented software. UML. U nified M odeling L anguage Goal:
E N D
COP 3503 FALL 2012ShayanJavedLecture 9 Programming Fundamentals using Java
UML • Unified Modeling Language
UML • Unified Modeling Language • Goal: • Common language for creating models of Object-Oriented software
UML • Unified Modeling Language • Goal: • Common language for creating models of Object-Oriented software • Two aspects: • Class Diagrams (Static design): Classes, Attributes, Relationships
UML • Unified Modeling Language • Goal: • Common language for creating models of Object-Oriented software • Two aspects: • Class Diagrams (Static design): Classes, Attributes, Relationships • Dynamic design: Objects, messages, finite state machines [Sequence/Activity/State Machine diagrams]
Class Diagrams • Depict classes within a model
Class Diagrams • Depict classes within a model • Classes have: • Attributes (Properties/Member Variables)
Class Diagrams • Depict classes within a model • Classes have: • Attributes (Properties/Member Variables) • Operations (Functions/Methods)
Class Diagrams • Depict classes within a model • Classes have: • Attributes (Properties/Member Variables) • Operations (Functions/Methods) • Relationships with other classes
Class Diagrams Class Properties Methods()
Class Diagrams GeometricObject color : String name : String area : double GeometricObject() GeometricObject(String, String) get() : String/double set(..) : void
Class Diagrams • Properties • name : type
Class Diagrams • Properties • name : type • Ex.: • area : double
Class Diagrams • Methods: • name(parameters) : return type
Class Diagrams • Methods: • name(parameters) : return type • Ex.: • getArea( ) : double
Class Diagrams • Methods: • name(parameters) : return type • Ex.: • getArea( ) : double • setColor(color : String) : void
Class Diagrams • Properties/Methods can be public/private/protected/static
Class Diagrams • Properties/Methods can be public/private/protected/static • Need a way to indicate that somehow
Class Diagrams • Properties/Methods can be public/private/protected/static • Need a way to indicate that somehow • Add a sign next to the property/method: • Public (+)
Class Diagrams • Properties/Methods can be public/private/protected/static • Need a way to indicate that somehow • Add a sign next to the property/method: • Public (+) • Private (-)
Class Diagrams • Properties/Methods can be public/private/protected/static • Need a way to indicate that somehow • Add a sign next to the property/method: • Public (+) • Private (-) • Protected(#)
Class Diagrams • Properties/Methods can be public/private/protected/static • Need a way to indicate that somehow • Add a sign next to the property/method: • Public (+) • Private (-) • Protected(#) • To indicate a static property/method, underline it
Class Diagrams • Final (constant) properties are declared by writing them in ALL_CAPS • (Math.PI for example)
Class Diagrams GeometricObject # Color : String # name : String # area : double + GeometricObject() + GeometricObject(String, String) + get() : String/double + set(..) : void
Class Diagrams • But GeometricObject is abstract
Class Diagrams • But GeometricObject is abstract • How do you differentiate between an abstract and non-abstract class/method?
Class Diagrams • But GeometricObject is abstract • How do you differentiate between an abstract and non-abstract class/method? • Italicize it
Class Diagrams GeometricObject # Color : String # name : String # area : double + GeometricObject() + GeometricObject(String, String) + get() : String/double + set(..) : void + getArea() : double
Class Diagrams • But can’t italicize when writing...
Class Diagrams • But can’t italicize when writing... • So to indicate abstract methods/classes on paper write {abstract} in brackets
Class Diagrams GeometricObject {abstract} # Color : String # name : String # area : double + GeometricObject() + GeometricObject(String, String) + get() : String/double + set(..) : void + getArea() : double {abstract}
Class Diagrams • Relationships between classes: • Generalization (Inheritance = “is a”)
Class Diagrams • Relationships between classes: • Generalization (Inheritance = “is a”) • Aggregation (“has a”)
Class Diagrams • Relationships between classes: • Generalization (Inheritance = “is a”) • Aggregation (“has a”) • Composition (“owns a”)
Class Diagrams • Generalization (Inheritance - “is a”): Circle - radius : double + Circle (...) + getRadius( ) : double + getArea( ) : double + setRadius(radius : double) : void
Class Diagrams • Generalization (Inheritance - “is a”): Circle GeometricObject
Class Diagrams • Generalization (Inheritance - “is a”): • Used to indicate inheritance relationship
Class Diagrams • Generalization (Inheritance - “is a”): Circle Rectangle GeometricObject
Class Diagrams • Aggregation (“has a”):
Class Diagrams • Aggregation (“has a”): • Class1 has a number of Class2
Class Diagrams • Aggregation (“has a”): • Class1 has a number of Class2 • Course has a number of Students • Course has manyStudents
Class Diagrams • Aggregation (“has a”): public Course { Student[] students = newStudent[capacity]; }
Class Diagrams • Aggregation (“has a”): public Course { Student[] students = newStudent[capacity]; } Student Course 0..capacity students
Class Diagrams • Aggregation (“has a”): • 0...capacity = number of students in the Course • “students” = the variable
Class Diagrams • Aggregation (“has a”): • 0...capacity = number of students in the Course • “students” = the variable • So aggregation indicated by empty diamond
Class Diagrams • Composition (“owns a”):
Class Diagrams • Composition (“owns a”): • Similar to Aggregation – but one class completely depends on the other.
Class Diagrams • Composition (“owns a”): • Similar to Aggregation – but one class completely depends on the other. • Destroying one also destroys the dependent class
Class Diagrams • Composition (“owns a”): Wheels Car 4 wheels