Presentation is loading. Please wait.

Presentation is loading. Please wait.

03/12/2001 © Bennett, McRobb and Farmer 2002 1 Designing Boundary Classes Based on Chapter 17 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis.

Similar presentations


Presentation on theme: "03/12/2001 © Bennett, McRobb and Farmer 2002 1 Designing Boundary Classes Based on Chapter 17 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis."— Presentation transcript:

1 03/12/2001 © Bennett, McRobb and Farmer 2002 1 Designing Boundary Classes Based on Chapter 17 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design Using UML, (2 nd Edition), McGraw Hill, 2002.

2 © Bennett, McRobb and Farmer 2002 2 In This Lecture You Will Learn: n What we mean by the presentation layer n How prototyping can be applied to user interface design n How to add boundary classes to the class model n How to model boundary classes in sequence diagrams n How design patterns can be applied to the user interface n How to model control using statecharts

3 © Bennett, McRobb and Farmer 2002 3 Architecture of the Presentation Layer n We aim to separate the classes that have the responsibility for the interface with the user, or with other systems, (boundary classes) from the business classes (entity classes) and the classes that handle the application logic (control classes) n This is the Three-Tier Architecture

4 © Bennett, McRobb and Farmer 2002 4 Presentation Layer n Handles interface with users and other systems n Formats and presents data at the interface n Presentation can be for display as text or charts, printing on a printer, speech synthesis, or formatting in XML to transfer to another system n Provides a mechanism for data entry by the user, but the events are handled by control classes

5 © Bennett, McRobb and Farmer 2002 5 Presentation Layer n Does not contain business classes— Clients, Campaigns, Adverts, Invoices, Staff etc. n Does not contain the business logic— rules like ‘A Campaign must have one and only one Campaign Manager’. n Doesn’t handle validation, beyond perhaps simple checks on formatting

6 © Bennett, McRobb and Farmer 2002 6 Reasons for the 3-Tier Architecture Logical design The project team may be producing analysis and design models that are independent of the hardware and software environment in which they are to be implemented. For this reason, the entity classes, which provide the functionality of the application, will not include details of how they will be displayed. Interface independence Even if display methods could be added to classes in the application, it would not make sense to do so. Object instances of any one class will be used in many different use cases: sometimes their attributes will be displayed on screen, sometimes printed by a printer. There will not necessarily be any standard layout of the attributes that can be built into the class definition, so presentation of the attributes is usually handled by another class. Reuse One of the aims is to produce classes that can be reused in different applications. For this to be possible, the classes should not be tied to a particular implementation environment or to a particular way of displaying the attribute values of instances.

7 © Bennett, McRobb and Farmer 2002 7 3-Tier Architecture n Different authors have used different terms –Boundary, Entity, Control –Model, View, Controller –Human Interaction Component, Problem Domain Component, Task Management Component (not necessarily in the same order)

8 © Bennett, McRobb and Farmer 2002 8 Developing Boundary Classes n Prototype the user interface n Design the classes n Model the interaction involved in the interface n Model the control of the interface using statechart diagrams (if necessary)

9 © Bennett, McRobb and Farmer 2002 9 Prototyping the User Interface n A prototype is a model that looks, and partly behaves, like the finished product but lacks certain features n A prototype of the user interface is a horizontal prototype—it prototypes one layer of the system n A vertical prototype takes a sub-system and prototypes all the layers

10 © Bennett, McRobb and Farmer 2002 10 Prototyping the User Interface n Distinction between –prototypes developed in an iterative process that are elaborated to become part of the eventual system and –prototypes developed to test out design ideas that are thrown away rather than being further enhanced (actually, they are not really thrown away, as they form part of the design)

11 © Bennett, McRobb and Farmer 2002 11 Check Campaign Budget Use Case Prototype n In this prototype, Clients and Campaigns are selected in drop-down lists n There are other ways…

12 © Bennett, McRobb and Farmer 2002 12 Check Campaign Budget Use Case Prototype n Using a treeview control…

13 © Bennett, McRobb and Farmer 2002 13 Check Campaign Budget Use Case Prototype n Using a separate look-up window

14 © Bennett, McRobb and Farmer 2002 14 Check campaign budget Use Case Prototype n Choice of approach is part of the style guidelines discussed in Chapter 16 n We are going to use the first approach, with drop-down lists n Although in Chapter 6, we looked at use cases for ‘Find campaign’, ‘Find client’ etc. as separate look-up windows, this approach is not what the Agate users want

15 © Bennett, McRobb and Farmer 2002 15 Designing Classes n Start with the collaborations from the analysis model n Elaborate the collaborations to include necessary boundary, entity and control classes n Rosenberg and Scott (1999) treat control classes as placeholders—they represent some responsibility that has to be handled somewhere, but it may become an operation of another class

16 © Bennett, McRobb and Farmer 2002 16 Collaboration for Check campaign budget n In order to find the right Campaign, we also need to use the Client class, even though it doesn’t participate in the real process of checking the budget n We also add control classes for the respons- ibilities of listing clients and campaigns Check Campaign Budget UI Check Campaign Budget CampaignAdvert

17 © Bennett, McRobb and Farmer 2002 17 Collaboration for Check campaign budget Check Campaign Budget UI Check Campaign Budget CampaignAdvert List Campaigns List Clients Client

18 © Bennett, McRobb and Farmer 2002 18 Alternative Collaboration for Check campaign budget Check Campaign Budget UI Check Campaign Budget CampaignAdvert List Campaigns List Clients Client List Campaigns UI List Clients UI

19 © Bennett, McRobb and Farmer 2002 19 Class Diagram for CheckCampaignBudgetUI 3 1 2 1 1 1 2 1 Dialog CheckCampaignBudgetUI LabelButtonTextFieldChoice

20 © Bennett, McRobb and Farmer 2002 20 Single Class for CheckCampaignBudgetUI n Draw in your own lines to show which attribute is which element of the interface CheckCampaignBudgetUI - clientLabel : Label - campaignLabel : Label - budgetLabel : Label - checkButton : Button - closeButton : Button - budgetTextField : TextField - clientChoice : Choice - campaignChoice : Choice

21 © Bennett, McRobb and Farmer 2002 21 Package Dependencies n Classes can be shown with package names 3 1 2 1 1 1 2 1 AWT::Dialog CheckCampaignBudgetUI AWT::LabelAWT::ButtonAWT::TextFieldAWT::Choice

22 © Bennett, McRobb and Farmer 2002 22 Package Dependencies n There is an «import» dependency between the two packages import java.awt.*; // In Java using System.Winforms; // in C# AWT Agate User Interface «import»

23 © Bennett, McRobb and Farmer 2002 23 Sequence Diagrams *getCost( ) Campaign Manager :Client:Advert:Campaign listCampaigns( ) *getCampaignDetails( ) checkCampaignBudget( ) getName( ) getOverheads( )

24 © Bennett, McRobb and Farmer 2002 24 Sequence Diagrams n The sequence diagram on the previous slide just shows the entity classes n We also have the collaboration diagram from an earlier slide showing the control and boundary classes n We now need to model the interaction more detail

25 © Bennett, McRobb and Farmer 2002 25 First Part of Sequence Diagram Campaign Manager :CheckCampaign Budget CheckCampaignBudget( ) :CheckCampaign BudgetUI ccbUI := Check Campaign BudgetUI( this ) :ListClients lc := ListClients( ) listAllClients( ccbUI ) *addClientName( name ) enable( )

26 © Bennett, McRobb and Farmer 2002 26 First Part of Sequence Diagram n The control class –creates the instance of the boundary class –creates the instance of the ListClients control class –passes to :ListClients a reference to the boundary class –:ListClients then sets the name of each client in turn into the boundary class by calling addClientname(name) repeatedly

27 © Bennett, McRobb and Farmer 2002 27 Using Interfaces n We don’t mean user interfaces! n Many boundary classes will need to list clients to allow the user to select a client The ListClients control class doesn’t need to know how the boundary class lists them The boundary class needs to implement the ClientLister interface and provide an implementation of the operation addClientName(String)

28 © Bennett, McRobb and Farmer 2002 28 Using Interfaces Attributes can be private, only accessed through the public interface «interface» ClientLister + addClientName(String) CheckCampaignBudgetUI - clientLabel : Label - campaignLabel : Label - budgetLabel : Label - checkButton : Button - closeButton : Button - budgetTextField : TextField - clientChoice : Choice - campaignChoice : Choice «use» ListClients + enable( ) + listAllClients(ClientLister)

29 © Bennett, McRobb and Farmer 2002 29 Java Implementation import java.awt.*; public class CheckCampaignBudgetUI extends Frame implements ClientLister { private Choice clientChoice;... public void addClientName(String name) { clientChoice.addItem(name); }... }

30 © Bennett, McRobb and Farmer 2002 30 listAllClients( ) Operation :Client:ListClients listAllClients( cl ) cl:ClientLister aClient := getNextClient( ) name := getName( ) * [ while more clients ] :Client:ListClients listAllClients( cl ) :ClientLister aClient := getNextClient( ) name := getName( ) * [ while more clients ] addClientName( name )

31 © Bennett, McRobb and Farmer 2002 31 Second Part of Sequence Diagram Campaign Manager :CheckCampaign Budget select client :CheckCampaign BudgetUI :ListCampaigns lc := ListCampaigns( ) listCampaigns( ccbUI, aClient ) *addCampaignName( name ) clientSelected( ) aClient := getSelectedClient( )

32 © Bennett, McRobb and Farmer 2002 32 Event-driven User Interface Event in :clientChoice is passed through to the main boundary class Campaign Manager :CheckCampaign Budget :CheckCampaign BudgetUI [evt.source = clientChoice] clientSelected( ) clientChoice :Choice select clientitemState Changed( evt )

33 © Bennett, McRobb and Farmer 2002 33 Revised Second Part of Sequence Diagram Campaign Manager :CheckCampaign Budget select client :CheckCampaign BudgetUI :ListCampaigns lc := ListCampaigns( ) listCampaigns( ccbUI, aClient ) *addCampaignName( name ) clientSelected( ) aClient := getSelectedClient( ) clearAllCampaignNames( )

34 © Bennett, McRobb and Farmer 2002 34 Final Part of Sequence Diagram Campaign Manager :CheckCampaign Budget select campaign :CheckCampaign BudgetUI campaignSelected( ) enableCheckButton( ) checkCampaignBudget( ) check budget *getCost( ) :Advert:Campaign getOverheads( ) getCampaignSelected( ) checkCampaignBudget( ) setBudget( )

35 © Bennett, McRobb and Farmer 2002 35 Adding to the Class Diagram From the sequence diagrams, we can see that the CheckCampaignBudgetUI class needs to implement both the ClientLister and the CampaignLister interfaces There are also additional operations that have been introduced, some of which will apply to any class that implements these interfaces (and therefore belong to the interfaces), and some of which belong to the CheckCampaignBudgetUI class

36 © Bennett, McRobb and Farmer 2002 36 «interface» ClientLister + addClientName(String) + clearAllClientNames( ) + removeClientName(String) CheckCampaignBudgetUI - clientLabel : Label - campaignLabel : Label - budgetLabel : Label - checkButton : Button - closeButton : Button - budgetTextField : TextField - clientChoice : Choice - campaignChoice : Choice «use» ListCampaigns + enable( ) + enableCheckButton( ) + getSelectedClient( ) + getSelectedCampaign( ) + setBudget(Currency) + listAllCampaigns(CampaignLister) + listCampaigns(CampaignLister, Client) «interface» CampaignLister + addCampaignName(String) + clearAllCampaignNames( ) + removeCampaignName(String) ListClients + listAllClients(ClientLister) «use» «interface» java::awt::event::ItemListener + itemStateChanged(ItemEvent evt)

37 © Bennett, McRobb and Farmer 2002 37 Using Design Patterns n More and more, libraries of classes are built around design patterns n In Smalltalk, the Model–View–Controller architecture is widely used n In Java, an approach is used in which objects register an interest in events, then when an event occurs all the objects that have registered are notified of the event

38 © Bennett, McRobb and Farmer 2002 38 Model–View–Controller /Controller /Model /View

39 © Bennett, McRobb and Farmer 2002 39 Java Listener Approach :Component User Event :ItemListener 1: itemStateChanged (ItemEvent evt) 2: Inspect Event :any:Class 4 Update Self 3: [Event of Interest] Notify Class of Event

40 © Bennett, McRobb and Farmer 2002 40 Java Approach n Various listeners for different kinds of user interface components –MouseListener –ItemListener –ActionListener All subinterfaces of EventListener

41 © Bennett, McRobb and Farmer 2002 41 Java2 Enterprise Edition (J2EE) Approach n J2EE is used for N-Tier distributed systems based on Enterprise Java Beans (EJB) n J2EE Core Patterns provides a pattern catalogue that uses the Model–View– Controller architecture

42 © Bennett, McRobb and Farmer 2002 42 Modelling the User Interface in Statechart Diagrams n Different approaches to using statecharts –Browne (1994), which was used in the 1 st edition –Horrocks (1999) used here –Both based on the original work of Harel (1987) –Recent work of Harel and Politi (1998)

43 © Bennett, McRobb and Farmer 2002 43 Horrocks’ Approach n Five tasks: –describe the high-level requirements and main user tasks –describe the user interface behaviour –define user interface rules –draw the statechart (and successively refine it) –prepare an event action table

44 © Bennett, McRobb and Farmer 2002 44 High-level Requirements The requirement here is that the users must be able to check whether the budget for an advertising campaign has been exceeded or not. This is calculated by summing the cost of all the adverts in a campaign, adding a percentage for overheads and subtracting the result from the planned budget. A negative value indicates that the budget has been overspent. This information is used by a campaign manager.

45 © Bennett, McRobb and Farmer 2002 45 User Interface Behaviour n The client dropdown displays a list of clients. When a client is selected, their campaigns will be displayed in the campaign dropdown. n The campaign dropdown displays a list of campaigns belonging to the client selected in the client dropdown. When a campaign is selected the check button is enabled. n The budget textfield displays the result of the calculation to check the budget. n The check button causes the calculation of the budget balance to take place. n The close button closes the window and exits the use case.

46 © Bennett, McRobb and Farmer 2002 46 Define User Interface Rules n User interface objects with constant behaviour –The client dropdown has constant behaviour. Whenever a client is selected, a list of campaigns is loaded into the campaign dropdown –The budget textfield is initially empty. It is cleared whenever a new client is selected or a new campaign is selected. It is not editable –The close button may be pressed at any time to close the window

47 © Bennett, McRobb and Farmer 2002 47 Define User Interface Rules n User interface objects with varying behaviour –The campaign dropdown is initially disabled. No campaign can be selected until a client has been selected. Once it has been loaded with a list of campaigns it is enabled –The check button is initially disabled. It is enabled when a campaign is selected. It is disabled whenever a new client is selected

48 © Bennett, McRobb and Farmer 2002 48 Define User Interface Rules n Entry and exit events –The window is entered from the main window when the Check Campaign Budget menu item is selected –When the close button is clicked, an alert dialogue is displayed. This asks ‘Close window? Are you sure?’ and displays two buttons labelled ‘OK’ and ‘Cancel’. If ‘OK’ is clicked the window is exited; if ‘Cancel’ is clicked then it carries on in the state it was in before the close button was clicked

49 © Bennett, McRobb and Farmer 2002 49 Draw the Statechart n We start with the top-level statechart for movement between the windows and dialogues Main Window Check Budget Window Alert Dialogue checkCampaignBudget MenuSelected( ) closeButtonClicked( ) ‘OK’ ‘Cancel’

50 © Bennett, McRobb and Farmer 2002 50 Draw the Statechart Client selection states are nested within the Check Budget Window state No Client Selected Client Selected clientSelected( )

51 © Bennett, McRobb and Farmer 2002 51 Draw the Statechart Campaign selection states are nested within the Client Selected state No Campaign Selected Campaign Selected campaignSelected( )

52 © Bennett, McRobb and Farmer 2002 52 Draw the Statechart Display of result states are nested within Campaign Selected state Blank Display Result checkButtonPressed( )

53 © Bennett, McRobb and Farmer 2002 53 Check Budget Window 2 Client Selected 3 No Campaign Selected 4 Campaign Selected campaignSelected( ) 5 Blank 6 Display Result checkButtonPressed( ) 1 No Client Selected clientSelected( ) Main Window7 Alert Dialogue checkCampaignBudget MenuSelected( ) closeButtonClicked( ) ‘OK’‘Cancel’ H*

54 © Bennett, McRobb and Farmer 2002 54 Draw the Statechart n Non-UML features: –Horrocks numbers the states –State variables can be shown in square brackets n Statechart can be simplified (as on next slide) n Rather than try to add all messages associated with transitions into the diagram, an Event–Action table can be used

55 © Bennett, McRobb and Farmer 2002 55 Check Budget Window 2 No Campaign Selected campaignSelected( ) 3 Blank 4 Display Result checkButtonPressed( ) 1 No Client Selected clientSelected( ) Main Window5 Alert Dialogue checkCampaignBudget MenuSelected( ) closeButtonClicked( ) ‘OK’‘Cancel’ H*

56 © Bennett, McRobb and Farmer 2002 56 Event–Action Table

57 © Bennett, McRobb and Farmer 2002 57 Revising the Sequence Diagrams and Class Diagrams n Producing the statechart diagram and the event–action table has identified some additional messages that will be sent to the user interface to control it n These will need to be added to the sequence diagrams and to the class diagram as operations of the UI class or of the lister interfaces

58 © Bennett, McRobb and Farmer 2002 58 Revised First Sequence Diagram Campaign Manager :CheckCampaign Budget CheckCampaignBudget( ) :CheckCampaign BudgetUI ccbUI := Check Campaign BudgetUI( this ) :ListClients lc := ListClients( ) listAllClients( ccbUI ) *addClientName( name ) disableCheckButton( ) enable( ) disableCampaignList( )

59 © Bennett, McRobb and Farmer 2002 59 Summary In this lecture you have learned about: n What we mean by the presentation layer n How prototyping can be applied to user interface design n How to add boundary classes to the class model n How to model boundary classes in sequence diagrams n How design patterns can be applied to the user interface n How to model control using statecharts

60 © Bennett, McRobb and Farmer 2002 60 References n Horrocks (1999) n Browne (1994) n Harel (1987) n Gamma et al. (1995) (For full bibliographic details, see Bennett, McRobb and Farmer)


Download ppt "03/12/2001 © Bennett, McRobb and Farmer 2002 1 Designing Boundary Classes Based on Chapter 17 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis."

Similar presentations


Ads by Google