CompSci 230 Software Construction Class Diagrams Version 1.1 of 2014-03-12: added learning objectives and DuckTestApp Version 1.2 of 2014-03-14: added slide 6 on default values in UML Agenda Topics: Reading Leigh Dodd’s discussion of the UML examples in his introductory lecture slides. If you actually want to learn this material… 2 Examples of class diagrams Navigation, visibility, named associations, and multiplicity in UML Interfaces and implementation, in UML Find your own examples of class diagrams on the web. Try to interpret them. Look for patterns. Talk about it within your study group. COMPSCI 230: S4 Learning Objectives Students will have a strong conceptual foundation for their future uses of the OO features of Java Students will be able to interpret a class diagram Worked examples in this lecture Students will be competent at the basic OO design patterns 3 Interfaces Implementing interfaces, composing classes, extending classes COMPSCI 230: S3 Example of Inheritance 4 Source: http://www.ldodds.com/lectures/intro2java/Lesson1.ppt COMPSCI 230: S4 Too much detail? 5 Source: http://www.ldodds.com/lectures/intro2java/Lesson1.ppt COMPSCI 230: S4 Simplify! (with a little more notation) Multiplicity: The arrowheads indicate that the taughtBy association is navigable in both directions, telling us that 6 There is exactly one teacher per course, as indicated by the 1. A lecturer can teach any number of courses, as indicated by 0..*. We can also write 1..* in a UML diagram. Course has an instance variable teacher, of type Lecturer, and Lecturer has the instance variable Vector<Course> course. COMPSCI 230: S4 Simplify even more, with defaults Associations have default multiplicity 1 Association endpoints have a default name. Getters, setters may be implied. Unimportant members might not be shown. Defaults may be well-defined by an organisation’s stylesheet, or (more commonly) by their UML-drawing software package. 7 Course has an instance variable myLecturer of type Lecturer Lecturer has an instance variable myCourse of type Vector<Course> See e.g. http://msdn.microsoft.com/enus/library/dd323861.aspx: “Properties of Attributes in UML Diagrams” for VS 2013. COMPSCI 230: S4 One-way Navigation These courses have a Vector of their Lecturers and Students. 8 (They might have a List; they might have an array; these are implementation decisions.) These lecturers don’t know what they are teaching! These students have no idea of what course they are taking! COMPSCI 230: S4 Creating new classes by generalising Lecturers and students have some attributes in common. We write these methods once for the Person class, and we can reuse them in the Lecturer and Student class. 9 A public name An email address that is revealed to everyone in our University A secret password But we have complicated our design by adding another class. Do we really need so many classes? COMPSCI 230: S4 Interfaces Interfaces are a way to specify behaviour (a public contract) without data or implementation. Interfaces are classed with an extra label next to their name: <<Interface>> A dotted open-triangle arrow, from a class to an interface means that “the class implements this interface”. 10 We also say that “the class fulfils the contract specified by this interface”, or that it “realizes the interface.” Note that interfaces define methods but not attributes. A password allows a secureLogin(). COMPSCI 230: S4 Can you understand this design? 11 Adapted from http://www.ldodds.com/lectures/intro2java/Lesson1.ppt COMPSCI 230: S4 Can you understand this design? 12 Source: http://commons.wikimedia.org/wiki/File:UML_diagram_ of_composition_over_inheritance.svg, available 2014-03-12. COMPSCI 230: S4 Don’t believe everything you read! In Quiz 1, over the weekend, you’ll be exploring the design space of the DuckTestApp on the previous slide. I hope this quiz inspires one or more of you to improve http://en.wikipedia.org/wiki/Composition_over_inheritance, so that its Example section discusses two class diagrams. The first class diagram could show a simple design for a DuckTestApp which relies solely on inheritance to model its ducks. The second diagram could show a more complicated but more extensible design which makes appropriate use of composition and realisation. Ideally, your discussion would mention that the Adapter design pattern was employed when the app was extended to handle turkey-testing as well as duck-testing. 13 Warning: the Wikipedia article on the Adapter design pattern is also in need of improvement. COMPSCI 230: S4 Learning Objectives (review) Students will have a strong conceptual foundation for their future uses of the OO features of Java Students will be able to interpret a class diagram Worked examples in this lecture Students will be competent at the basic OO design patterns 14 Interfaces Implementing interfaces, composing classes, extending classes COMPSCI 230: S3
© Copyright 2024