Presentation is loading. Please wait.

Presentation is loading. Please wait.

Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Similar presentations


Presentation on theme: "Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()"— Presentation transcript:

1 Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating() Customer getName() checkCreditRating()

2 Winter 2007ACS-3913 Ron McFadyen2 Classes « Singleton » dbFacade Some classes are stereotyped: Later in the course we study the Singleton design pattern. Some methodologies have 3 stereotypes for “analysis” classes: boundary, control, entity

3 Winter 2007ACS-3913 Ron McFadyen3 Class Diagram Navigability In the example below, student could be implemented with a history attribute: StudentHistory * -history[0..*] : History history[0..*] provides for the association to be navigated – we can send a message to a History object

4 Winter 2007ACS-3913 Ron McFadyen4 Instances Joe: Customer Class instances An individual object (instance of a class) is shown with naming information underlined An unnamed customer : Customer A customer named Joe

5 Winter 2007ACS-3913 Ron McFadyen5 Diagramming notation :sale s4:sale A sale object named s4 An unnamed sale object s4 An object named s4 Sale The class Sale

6 Winter 2007ACS-3913 Ron McFadyen6 Attributes an object contains data which are defined as part of the Class definition examples: Students have names, addresses, etc; Courses have titles, descriptions, prerequisite information. Rectangle corner: Point Student name address Level of detail present will depend on whether you are in analysis or design, and your purposes at the time

7 Winter 2007ACS-3913 Ron McFadyen7 Attributes To what degree is an attribute visible to other classes? Private – Public + Protected # Package ~ Student -name -address

8 Winter 2007ACS-3913 Ron McFadyen8 Attributes Default values = Derived values / Multiplicity [ ] Ordering{ordered} Uniqueness{unique} Invoice -date:Date = today -/total: Currency -payments[0..*]: Currency Student -name -address[1..3] {unique}

9 Winter 2007ACS-3913 Ron McFadyen9 Operations. What are the responsibilities of a class? What can it do? Visibility Parameters Signaturethe name, parameters, and return type of the operation Student +getName() +getGPA(term :Term, gpaType: String)

10 Winter 2007ACS-3913 Ron McFadyen10 Associations correspond to verbs expressing a relationship between classes example a Library Member borrows a Copy of a Book Multiplicities we indicate via multiplicities the range of allowable cardinalities for participation in an association examples: 1, 1..*, 0..*, 1..3

11 Winter 2007ACS-3913 Ron McFadyen11 Associations Names and roles you can name the relationship and indicate how to read it you can give role names for participating objects PersonCompany Works for 1..* 1 employer employee The role of a Person in this relationship The role of a Company in this relationship The name of the relationship and the direction for reading the name

12 Winter 2007ACS-3913 Ron McFadyen12 Associations example: a Library Member borrows a Copy of a Book MemberBook * * borrower borrows

13 Winter 2007ACS-3913 Ron McFadyen13 Associations example: An employee is supervised by an employee * 0,1 Employee reports to supervised supervisor A reflexive association

14 Winter 2007ACS-3913 Ron McFadyen14 Interfaces An interface is special type of class that cannot be instantiated. An application can never instantiate an interface. An interface defines a set of public attributes and operations that some class must use (depends on) There is no behaviour defined, no method coded Some other class inherits the interface and provides the implementation

15 Winter 2007ACS-3913 Ron McFadyen15 From Head First … package headfirst.observer.weatherobservable; import java.util.Observable; import java.util.Observer; public class ForecastDisplay implements Observer, … public void update(Observable observable, Object arg) { if (observable instanceof WeatherData) { WeatherData weatherData = (WeatherData)observable; lastPressure = currentPressure; currentPressure = weatherData.getPressure(); display(); } public void display() { System.out.print("Forecast: "); if (currentPressure > lastPressure) { System.out.println("Improving weather on the way!"); } …

16 Winter 2007ACS-3913 Ron McFadyen16 From Head First … package headfirst.observer.weatherobservable; import java.util.Observable; import java.util.Observer; public class StatisticsDisplay implements Observer, DisplayElement { private float maxTemp = 0.0f; … public void update(Observable observable, Object arg) { if (observable instanceof WeatherData) { WeatherData weatherData = (WeatherData)observable; float temp = weatherData.getTemperature(); … display(); } public void display() { System.out.println("Avg/Max/Min temperature = " …

17 Winter 2007ACS-3913 Ron McFadyen17 From Head First … > Observer ForecastDisplay update() These classes implement the update operation StatisticsDisplay

18 Winter 2007ACS-3913 Ron McFadyen18 Sequence Diagram Objects are represented horizontally across the top of the diagram Each object has a lifeline some exist before and/or after some are created during some are destroyed during An active object is indicated by a narrow rectangle Focus of control Time is represented vertically down the diagram. Time moves forward as you go downwards Iteration is shown with a frame

19 Winter 2007ACS-3913 Ron McFadyen19 Sequence Diagram Message types Synchronous Asynchronous Creation Reply Synchronous A message from one object to another object, and where the first object must wait until the resulting action completes. Reply Represents an explicit return of control. Not often used.

20 Winter 2007ACS-3913 Ron McFadyen20 : register: sale : payment makePayment() payment() sd Make payment Sequence Diagram named Make payment Object is created

21 Winter 2007ACS-3913 Ron McFadyen21 X : register: sale : payment makePayment() payment() sd Make Payment Object is destroyed

22 Winter 2007ACS-3913 Ron McFadyen22 Message to ‘self’ A reflexive message : sale calcTotal() getTotal()

23 Winter 2007ACS-3913 Ron McFadyen23 Iteration :Sale :SalesLineItem t=getTotal() st = getSubTotal() loop [I < numItems] loop is one of the keywords you can use to specify the nature of the fragment

24 Winter 2007ACS-3913 Ron McFadyen24 client getInstance() alt Behaviour in Singleton Pattern :CarMatchOffice CarMatchOffice() Inst=CarMatchOffice() getInstance() [inst == null] [else] getAddress() When you ask for the instance of CarMatchOffice, there are two ways it can complete. CarMatchOffice

25 Winter 2007ACS-3913 Ron McFadyen25 Collaborations Collaboration : an arrangement of classes, links, roles in a context to implement some behaviour. Useful for showing a system’s applications of patterns. Name of pattern appears in a dashed oval. Links to classes shown with participation roles. The value of using collaborations on your class diagram is to show what patterns you have used and the roles that classes and objects will be playing.

26 Winter 2007ACS-3913 Ron McFadyen26 Weather Station Class Diagram «interface» Subject attach() detach() notify() «interface» Observer update() WeatherData attach() detach() notify() CurrentConditionsDisplay update() display() * StatisticsDisplay update() display() ForecastDisplay update() display() «interface» DisplayElement display()

27 Winter 2007ACS-3913 Ron McFadyen27 Class Diagram showing Observer Collaboration «interface» Subject attach() detach() notify() «interface» Observer update() WeatherData attach() detach() notify() CurrentConditionsDisplay update() display() * StatisticsDisplay update() display() ForecastDisplay update() display() «interface» DisplayElement display() Observer subject observer Concrete subject Concrete observer


Download ppt "Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()"

Similar presentations


Ads by Google