26
1 Ari Jaaksi 1997 / Roope Raisamo 2000 MVC++ application architecture Ari Jaaksi

MVC++ application architecture

  • Upload
    cachet

  • View
    65

  • Download
    1

Embed Size (px)

DESCRIPTION

MVC++ application architecture. Ari Jaaksi. MVC++ application architecture. Model View Controller C++ OMT++ = MVC++. OMT (Rumbaugh et al./ GE). “OMT/NMS” (NTC). Fusion (Coleman et al. / HP). OMT+ (Nokia). UML (Rumbaugh, Booch, Jacobson / Rational). OMT++ (Nokia Networks). - PowerPoint PPT Presentation

Citation preview

Page 1: MVC++ application architecture

1 Ari Jaaksi 1997 / Roope Raisamo 2000

MVC++ application architecture

Ari Jaaksi

Page 2: MVC++ application architecture

2 Ari Jaaksi 1997 / Roope Raisamo 2000

MVC++ application architecture

ModelView

ControllerC++

OMT++=

MVC++

ModelView

ControllerC++

OMT++=

MVC++

Page 3: MVC++ application architecture

3 Ari Jaaksi 1997 / Roope Raisamo 2000

OMT++OMT (Rumbaugh et al./ GE)

“OMT/NMS” (NTC) Fusion (Coleman et al. / HP)

OMT+ (Nokia)

OMT++ (Nokia Networks)

UML (Rumbaugh, Booch, Jacobson / Rational)

Page 4: MVC++ application architecture

4 Ari Jaaksi 1997 / Roope Raisamo 2000

OMT++ process

ClassSpecification

ClassImplementation

Dialogue Diagrams,Operation Specifications

ClassDeclarations

Implementationof Methods

OOD

OOP

Object Analysis

Behaviour Analysis

User Interface Specification

DesignClass Diagrams

Sequence Diagrams,Statechart Diagrams

Object Design

BehaviourDesign

AnalysisClass Diagrams

Operations,Use Cases

OOA

Page 5: MVC++ application architecture

5 Ari Jaaksi 1997 / Roope Raisamo 2000

MVC & OMT++ & C++ => MVC++

• Original MVC (SmallTalk) is Adapted to C++

• Adapted to Java programs

• Essential part of OMT++

• Based on agreements• naming• division of labour• communication

• Base classes

• Text templates

Page 6: MVC++ application architecture

6 Ari Jaaksi 1997 / Roope Raisamo 2000

“GUI-Hanger” syndrome

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

FuncX(…){ do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that; do this; do that;}

Page 7: MVC++ application architecture

7 Ari Jaaksi 1997 / Roope Raisamo 2000

Some application architectures

Min=0Max=400Value=50

Abstraction Control Presentation

PAC (J.Coutaz)

Controller View

Model

MVC Model (Reenskaug)

Application Userinterface

Simple Separation (N.N)

Frame

View

Document

Document

View

MDI (MFC)

Page 8: MVC++ application architecture

8 Ari Jaaksi 1997 / Roope Raisamo 2000

Objectives of MVC++1. To separate applications into parts which each have their own job and purpose,2. To get more reusable software components,3. To make software easier to maintain and understand,4. To fill the gap between the analysis and design phases

VIEW

CONTROLLER

MODEL

Page 9: MVC++ application architecture

9 Ari Jaaksi 1997 / Roope Raisamo 2000

MVC++ triad

Controller-knows how this particular application works-controls the view and the model

Model-"real world"-works when the controller asks it to work

View-user interface-knows how to communicatewith the end user

Page 10: MVC++ application architecture

10 Ari Jaaksi 1997 / Roope Raisamo 2000

MVC++ application in action

Actions ofthe End User

=Manipulation

Observations ofthe End User=Feedback

End User View Controller Model

Decisions

Interpretedactions

Results

Actions

Action requests

Action requests

UserInterface

Page 11: MVC++ application architecture

11 Ari Jaaksi 1997 / Roope Raisamo 2000

Working together

Balance:7800:-

ModelControllerView

controller::BalanceWanted(){ b = model->GetBalance(); view->ShowBalanceFM(b);};

7800.00

Balance

Get

view::GetPressedMM(){ controller->BalanceWanted();};

view::ShowBalanceFM(int b){ TextField.WriteInt(b);};

int model::GetBalance(){

return(balance);};

Page 12: MVC++ application architecture

12 Ari Jaaksi 1997 / Roope Raisamo 2000

A typical MVC task

controller

viewmodel

useracts

2.1.

3.

4.

5.

6.

7.8. 9.

10.

1. The end user manipulates the view (e.g. presses a button).2. The user's actions are interpreted by the view.3. The view passes the interpreted commands to the controller.4. The controller decides what should be done in a situation like this.5. According to its own intelligence the controller makes the model act.6. The model acts independently. 7. After the model has completed the tasks, the control returns to the controller. It decides if the changes in the model should cause changes in the view. 8. If so, the controller gets all the information needed from the model.9. The controller passes the information to the view. 10. The view displays the information in its own way.

Page 13: MVC++ application architecture

13 Ari Jaaksi 1997 / Roope Raisamo 2000

View layer• the user interface

• contains e.g. the windowing system• all the callback functions of the windowing system• all the widgets of the windowing system

• knows how to communicate with the end user• knows how to present things to the end user• knows how to receive the end user’s actions

• does not decide what to do with the user’s actions• lets the controller decide

• has feedback, manipulation and query methods• has methods like ShowObjectIDFM(), PresentBTSStateFM() to present things to the end user,• has methods like ButtonXXXPressedMM(), SliderYYYMovedMM() to capture the end user’s actions,• has methods like GetSelectionQM(), GetChosenElementQM() to capture the end user’s selections made some time ago

• is instantiated by the controller; communicates with the controller

Page 14: MVC++ application architecture

14 Ari Jaaksi 1997 / Roope Raisamo 2000

Model layer

• the “real world”

• is capable of completing “real world” tasks independently

• is controlled by the controller

•the controller makes the model act

• the model is not aware of the view

• has methods like GetObjectID(), ChangeBTSState() etc.

Page 15: MVC++ application architecture

15 Ari Jaaksi 1997 / Roope Raisamo 2000

Controller layer• brains of the application

• makes application specific decisions• knows how this application should behave

• controls the application by making the model and the view act

• knows WHAT the model and the view are capable of doing• knows WHAT the model and the view should do • doesn’t know HOW things are done inside the model and the view

• instantiates the view and often the model too

• has corresponding methods for manipulation methods of the view

• a typical task:1. Gets the user’s commands interpreted by the view.2. Decides what to do with user’s commands.3. Asks the model to work. (model->ChangeBTSState(...);)4. Asks the view to present the results.

(view->PresentBTSStateFM(...);)

Page 16: MVC++ application architecture

16 Ari Jaaksi 1997 / Roope Raisamo 2000

Some facts ...• view part consists of view objects

• controller part consists of controller objects

• model part consists of model objects

• every controller class has a view class of its own

• every view class has a controller class of its own

• there are typically many controller-view class pairs in an application

• there is the main controller controlling the main window and all other controllers

• normally every window/dialogue of an application forms a view class

Page 17: MVC++ application architecture

17 Ari Jaaksi 1997 / Roope Raisamo 2000

«controller»MainController

MVC++ application

«view»MainView

«view»SubViewA

«view»SubViewB

ModelA

ModelC

ModelD

ViewLayer

ControllerLayer

ModelLayer

«controller»SubControllerA

«controller»SubControllerB

ModelB

1 1 1

1

*

Could be anycardinality

1

11

1

Page 18: MVC++ application architecture

18 Ari Jaaksi 1997 / Roope Raisamo 2000

«controller»MainController

Very simple view objects

«view»MainView

«view»SubViewA

«controller»SubControllerA

«view»SubViewB

«controller»SubControllerB

ModelA

ModelB ModelC

ModelD

VerySimpleView

VerySimpleView

1 1 1

11

1

11

Page 19: MVC++ application architecture

19 Ari Jaaksi 1997 / Roope Raisamo 2000

Methods of the view• There are three main categories of methods in a view class:

• Manipulation Methods (MM)callback methods, associated with widgets

these methods typically call the controller• Feedback Methods (FM)

these methods are used by the controller

show things to the end user• Query Methods (QM)

these methods are used by the controller

investigate the state of the view

xxxView::ButtonPressedMM(){

controller->ActionWanted();}

A Manipulation Method

xxxView::ShowTextFM(char *txt){

XmTextSetString(widgetX,txt);}

A Feedback Method

char *xxxView::GetNameQM(){

return(XmTextGetString(widgetY));}

A Query Method

Page 20: MVC++ application architecture

20 Ari Jaaksi 1997 / Roope Raisamo 2000

Constructing an MVC hierarchy

Model C

Main Controller Main ViewMainProgram

Controller A Controller B

View A View B

1. Creates 2. Creates

5. Creates 8. Creates

4. Creates 7. Creates

3. Creates

Model A Model B

9. Creates6. Creates

0. The main program creates an instance of the program object of the application.1. The program object creates the main controller.2. The main controller creates the view that initializes the windowing system3. The main controller creates its model.4. The main controller creates controller A5. Controller A creates its view.6. Controller A creates its model.7. The main controller creates controller B8. Controller B creates its view.9. Controller B creates its model.

Page 21: MVC++ application architecture

21 Ari Jaaksi 1997 / Roope Raisamo 2000

Constructing an MVC hierarchy #2

0. The main program creates an instance of the program object of the application.1. The program object creates the main controller.2. The main controller creates the view that initializes the windowing system3. The main controller creates the model.4. The main controller creates the controller A5. Controller A creates its view.6. The main controller sets a link between the controller A and the model.7. The main controller creates the controller B8. Controller B creates its view.9. The main controller sets a link between controller B and the model.

Model C

Main Controller Main ViewMainProgram

Controller A Controller B

View A View B

1. Creates 2. Creates

5. Creates 8. Creates

4. Creates7. Creates

3. Creates

6. Sets6. Sets

Page 22: MVC++ application architecture

22 Ari Jaaksi 1997 / Roope Raisamo 2000

Attempt to connect a view anda controller class

xxxView_c...xxxcontroller->ActionAsked()

uses

xxxController_c{

public:ActionAsked();

};

xxxView_c...xxxcontroller->ActionAsked()

uses

yyyController_c{

public:ActionAsked();

};

NJET!

1

1

1 1

1

1

Page 23: MVC++ application architecture

23 Ari Jaaksi 1997 / Roope Raisamo 2000

Connecting view and controller

xxxView_c...xxxAbsViewPartner->ActionAsked()

xxxController_c: public xxxAbsViewPartner{

public:ActionAsked();

};

xxxAbsViewPartner_c{

ActionAsked{abstract}};

uses xxxView_c...xxxAbsViewPartner->ActionAsked()

yyyController_c: public xxxAbsViewPartner{

public:ActionAsked();

};

xxxAbsViewPartner_c{

ActionAsked{abstract}};

uses

Da!

Page 24: MVC++ application architecture

24 Ari Jaaksi 1997 / Roope Raisamo 2000

Abstract partners

MainController

SomeController

MainView

SomeView

Model A Model B

AbstractMain ViewPartner

AbstractSome ViewPartner

Abstract SomeControllerPartner

Program

uses

uses

uses

1

Page 25: MVC++ application architecture

25 Ari Jaaksi 1997 / Roope Raisamo 2000

Base classes

«mvclib»MVCBase_c

«mvclib»MVCProgramBase_c

«mvclib»MVCControllerBase_c

«mvclib»MVCViewBase_c

ownPrg_c ownMainCo_c

«mvclib» MVCModelBase_c

ownModel_c

«mvclib»MVCMainController

Base_c

«mvclib»MVCSubController

Base_c

«mvclib»MVCSubViewBase_c

«mvclib»MVCMainView

Base_c

ownSubCo_c ownMainVi_cownSubVi_c

uses

Page 26: MVC++ application architecture

26 Ari Jaaksi 1997 / Roope Raisamo 2000

References

• Krasner G.E., Pope S.T., "A Cookbook for Using the Model-View-Controller User Interface Paradigm in Smalltalk-80", Journal of Object-Oriented Programming, August/September, 1988.

• Jaaksi A., “Object-Oriented Development of Interactive Systems”, Diss. Tampere University of Technology, Publications 201, 1997.

• Jaaksi et al., “Tried & True Object Development - Industry-Proven Approaches with UML”, Cambridge University Press, 1999.

• NET internal training material, slidesets...