Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jan 29, 200391.3913 Ron McFadyen1 UML Class Diagram Examples Based on well-known patterns Exhibit ways of providing dynamic structures and behaviour.

Similar presentations


Presentation on theme: "Jan 29, 200391.3913 Ron McFadyen1 UML Class Diagram Examples Based on well-known patterns Exhibit ways of providing dynamic structures and behaviour."— Presentation transcript:

1 Jan 29, 200391.3913 Ron McFadyen1 UML Class Diagram Examples Based on well-known patterns Exhibit ways of providing dynamic structures and behaviour

2 Jan 29, 200391.3913 Ron McFadyen2 UML Class Diagram Example 1 Example of the Decorator pattern: the intent is to attach additional responsibilities to an object dynamically We create a chain of objects that start with the decorator objects and ending with the original object In this example, SalesTicket is the original object and headers and footers are the decorators We will be able to build chains of objects with a varying number of headers, a ticket, and a varying number of footers: –Header1  Header2  Footer1  SalesTicket –Header1  Footer1  SalesTicket

3 Jan 29, 200391.3913 Ron McFadyen3 UML Class Diagram Example 1 SalesTicket Component HeaderFooter TicketDecorator 1 0,1

4 Jan 29, 200391.3913 Ron McFadyen4 UML Class Diagram Example 2 In this example, the original object is an input stream and the decorators are actions to be performed on the input stream We can build chains of objects with a varying number of actions to be applied in turn to an input file: –decrypt  decompress  grades file –run checksum  decrypt  unzip  payroll file –run checksum  decrypt  unzip  a string

5 Jan 29, 200391.3913 Ron McFadyen5 UML Class Diagram Example 2 String Component DecryptChecksum Action 1 0,1 File Source DecompressUnzip

6 Jan 29, 200391.3913 Ron McFadyen6 UML Class Diagram Example 3 In this example, the original object is a text view and the decorators add more to the appearance of the text view We can build chains of objects with a varying number of actions to be applied in turn to an input file: –border  scrollbar  text view

7 Jan 29, 200391.3913 Ron McFadyen7 UML Class Diagram Example 3 Text view Component BorderDecorator Decorator 1 0,1 ScrollDecorator

8 Jan 29, 200391.3913 Ron McFadyen8 UML Class Diagram Example 4 In this example, based on the Composite pattern, a diagram is considered a complex construction of lines, rectangles, text, etc. and these can be combined into pictures generating a tree structure: pic1:Picture pic2:Picturetext1:Texttext2:Textl1:Line r1:Rectangletext3:Textl2:Line

9 Jan 29, 200391.3913 Ron McFadyen9 UML Class Diagram Example 4 Line Component Composite * RectangleText

10 Jan 29, 200391.3913 Ron McFadyen10 UML Class Diagram Example 5 This example is based on the Proxy pattern Suppose you have a document that has a number of images and for some images you may have a proxy, something that stands for/ looks like/ act like the real thing. When the document is being formatted for display the document can send a message to the graphic asking it to display itself: a simple box if the image is still on disk; the image itself if its available doc1:Documentproxy1:Proxy proxy5:Proxy forest:Image tree:Image

11 Jan 29, 200391.3913 Ron McFadyen11 UML Class Diagram Example 5 Image Graphic ImageProxy 0,11 Document 1 *

12 Jan 29, 200391.3913 Ron McFadyen12 UML Class Diagram Example 6 This example is based on the Observer pattern Note the directed line – this indicates a unidirectional association where messages can only be sent in that direction. Note the dashed lines – we have interface inheritance in this case Suppose an alarm needs to notify each of its listeners when a certain event occurs. We arrange for this by having the subscribers register with the publisher, who places them on its notify list. When the event occurs the publishers sends each subscriber a message. More detail later on in course

13 Jan 29, 200391.3913 Ron McFadyen13 UML Class Diagram Example 6 alarmWindow Observer Beeper Publisher 1 * alarmClock


Download ppt "Jan 29, 200391.3913 Ron McFadyen1 UML Class Diagram Examples Based on well-known patterns Exhibit ways of providing dynamic structures and behaviour."

Similar presentations


Ads by Google