Transcript
Page 1: SOEN 6011 Software Engineering Processes

SOEN 6011Software Engineering Processes

Section SS Fall 2007

Dr Greg Butlerhttp://www.cs.concordia.ca/~gregb/home/soen6011-f2007.html

Page 2: SOEN 6011 Software Engineering Processes

Week 7• Responsibility-Driven Design

• Layer Architecture

• Model-View-Control

• Fowler’s EAA Patterns– Anatomy of a web site– Controller, Command patterns– Front Controller– Data Management patterns– Domain and DataMapper

Page 3: SOEN 6011 Software Engineering Processes

What is Design?Developing a blueprint (plan) for a

mechanism that performs the required task,

… taking into account all the constraints, &

… making trade-offs between constraints when they are in conflict.

Page 4: SOEN 6011 Software Engineering Processes

What is OO Analysis and Design• Object-Oriented

Analysis

– Important domain concepts or objects?

– Vocabulary?

– Visualized in the UP Domain Model

• Object-Oriented Design

– Design of software objects

– Responsibilities– Collaborations

– Design patterns

– Visualized in the UP Design Model

Page 5: SOEN 6011 Software Engineering Processes

Evolutionary Design

• What is the probability that a S/W design will need to be updated?

• Change is inevitable, evolutionary design recognizes this.

• As software is changed, generally it becomes more complex unless effort is made to keep it simple.

Page 6: SOEN 6011 Software Engineering Processes

Prerequisites to Successful Evolutionary Design?

• Testing– … lots of automated testing.

• Refactoring– … keeping the design simple.

• Continuous integration

• Actually, testing is a prerequisite to refactoring.

Page 7: SOEN 6011 Software Engineering Processes

Responsibility-Driven Design (RDD)

• Detailed object design is usually done from the point of view of the metaphor of:– Objects have responsibilities– Objects collaborate

• Responsibilities are an abstraction.– The responsibility for persistence.

• Large-grained responsibility.

– The responsibility for the sales tax calculation.• More fine-grained responsibility.

Page 8: SOEN 6011 Software Engineering Processes

Object Responsibilities

• A responsibility is an obligation of an object in terms of its behavior.

Page 9: SOEN 6011 Software Engineering Processes

General Classification of Kinds of Responsibility

– To know.– To do.– To decide.

Page 10: SOEN 6011 Software Engineering Processes

Responsibilities – A Boat Metaphor

• What kind of responsibilities do each of the following “objects” have: …– To know.– To do.– To decide.

Page 11: SOEN 6011 Software Engineering Processes

Responsibilities – A Boat Metaphor

Kind of responsibility for:

• Captain– To know?– To do?– To decide?

Page 12: SOEN 6011 Software Engineering Processes

Responsibilities – A Boat Metaphor

Kind of responsibility for:

• Navigator.– To know?– To do?– To decide?

Page 13: SOEN 6011 Software Engineering Processes

Responsibilities – A Boat Metaphor

Kind of responsibility for:

• Compass.– To know?– To do?– To decide?

Page 14: SOEN 6011 Software Engineering Processes

Important Concepts

Model• Abstraction hiding (unimportant) details• Eg, cover of Larman’s book

GRASP Principle• for assigning responsibility

Design pattern• Solution to design problem in context• Eg, Command pattern

Page 15: SOEN 6011 Software Engineering Processes

The 9 GRASP Principles

1. Creator2. Expert3. Controller4. Low Coupling5. High Cohesion6. Polymorphism7. Pure Fabrication8. Indirection9. Protected Variations

Page 16: SOEN 6011 Software Engineering Processes

Can you pick out a good design?

• What is a good design?– Satisfies user needs.– Is a simple as possible. Kent Beck:

• Runs all tests• Reveals intention.• No duplication.• Fewest number of classes or methods

• … can you smell bad design choices?

Page 17: SOEN 6011 Software Engineering Processes

•Present solutions to common software problems arising within a certain context

Overview of Patterns

•Capture recurring structures & dynamics among software participants to facilitate reuse of successful designs

The Proxy Pattern

1 1Proxy

service

Service

service

AbstractService

service

Client

•Help resolve key software design forces

•Flexibility•Extensibility•Dependability•Predictability•Scalability•Efficiency

•Generally codify expert knowledge of design strategies, constraints & “best practices”

Page 18: SOEN 6011 Software Engineering Processes

Layered Architectural Style

Our focus today:

• Architectural style: Layered.

• References– Larman, Chapter 13.– Fowler, EA.

• Briefly, lets review Client-Server

Page 19: SOEN 6011 Software Engineering Processes

Layered Style Characteristics

• Each layer offers services to layers above.

• Hence, layers build upon each other to provide increased functionality.

Page 20: SOEN 6011 Software Engineering Processes

Layering – Pure Style

• Pure style: components are permitted to use services of other components in– same layer.– layer immediately below.

Not permitted in pure style

Page 21: SOEN 6011 Software Engineering Processes

Client-Server (Two-tiered System)

• “… most people see tier as implying a physical separation. Client-server systems are often described as two-tier systems …” [Fowler,p19]

Page 22: SOEN 6011 Software Engineering Processes

Enterprise Application Layers

Calculate taxesAuthorizepayments

Database

Page 23: SOEN 6011 Software Engineering Processes

Enterprise Application Layers

PresentationDomain LogicData Source

Page 24: SOEN 6011 Software Engineering Processes

Layering – General Scheme

Layers

• Presentation / Application.– UI.– Generally “thin”.– (Term “application” can be misleading. It does not mean …)

• Domain / Business Logic.– Core system functionality.

• Technical Services.

Page 25: SOEN 6011 Software Engineering Processes

General Layering Scheme Refined

Presentation

Domain

Technical services

• Presentation• Application

• Domain (logic)• Low-level domain logic

• Technical services• Foundation.

Page 26: SOEN 6011 Software Engineering Processes

Typical Software Architecture Layers

UI(AKA Presentation, View)

Application(AKA Workflow, Process,Mediation, App Controller)

Domain(AKA Business,

Application Logic, Model)

Technical Services(AKA Technical Infrastructure, High-level Technical Services)

Foundation(AKA Core Services, Base Services,

Low-level Technical Services/Infrastructure)

width implies range of applicability

GUI windowsreportsspeech interfaceHTML, XML, XSLT, JSP, Javascript, ...

handles presentation layer requestsworkflowsession statewindow/page transitionsconsolidation/transformation of disparate data for presentation

handles application layer requestsimplementation of domain rulesdomain services (POS, Inventory)- services may be used by just one application, but there is also the possibility of multi-application services

(relatively) high-level technical services and frameworks Persistence, Security

low-level technical services, utilities, and frameworksdata structures, threads, math, file, DB, and network I/O

moreapp

specific

depe

nden

cy

Business Infrastructure(AKA Low-level Business Services)

very general low-level business services used in many business domainsCurrencyConverter

Page 27: SOEN 6011 Software Engineering Processes

Typical Software Architecture Layers (Simplified)

Domain

UI

Swingnot the Java Swing libraries, but our GUI classes based on Swing

Web

Sales Payments Taxes

Technical Services

Persistence Logging RulesEngine

Page 28: SOEN 6011 Software Engineering Processes

Laye

r D

epen

denc

ies

Exa

mpl

e

Log4J

Technical Services

Domain

Presentation

JessPersistence

POSRuleEngine

Inventory

PaymentsServiceAccess

PricingSales

TextSwing

SOAP

Page 29: SOEN 6011 Software Engineering Processes

Domain Logic (Layer)

• “… also referred to as business logic. … It involves calculations based on inputs and stored data, validation of any data that comes in from the presentation, and figuring out exactly what data source logic to dispatch …” [Fowler, p.20]

Page 30: SOEN 6011 Software Engineering Processes

Logical Architecture – Layers & Partitions

Persistence Security Logging

Technical Services

POS Inventory Tax

Domain

Vertical Layers

Horizontal Partitions

Page 31: SOEN 6011 Software Engineering Processes

Dom

ain

Data

Sou

rce

Transaction Script Domain Model

Data Mapper

Row Data Gateway

Front Controller

Template View

Transform View

Page Controller

Pres

enta

tion

Active Record

Fowler’s EA Patterns

Table Module

Table Data Gateway

Page 32: SOEN 6011 Software Engineering Processes

Enterprise Applications Patterns

Assignments (and some lectures) are about building web-based systems for enterprise applications

InvolvePresentation on the webBusiness Logic and Business ObjectsData storage and access

use book of Martin Fowler, “Patterns of Enterprise Application Architecture”

Page 33: SOEN 6011 Software Engineering Processes

Design Model

: Register

enterItem(itemID, quantity)

: ProductCatalog

spec = getProductSpec( itemID )

Require-ments

Business Modeling

Design

Sample UP Artifact Relationships

Vision Glossary

The logical architecture is influenced by the constraints and non-functional requirements captured in the Supp. Spec.

Domain Model

**

SupplementarySpecification

Use-Case Model

Register

...

makeNewSale()enterItem(...)...

ProductCatalog

...

getProductSpec(...)...

1 1class diagrams(a static view)

interaction diagrams(a dynamic view)

UIpackage diagramsof the logical architecture(a static view) Domain

Tech Services

Design Model

Page 34: SOEN 6011 Software Engineering Processes

Model-View Separation Principle (MVC)

UI layer has viewsDomain layer has model

Domain

UI

Swingnot the Java Swing libraries, but our GUI classes based on Swing

Web

Sales Payments Taxes

Technical Services

Persistence Logging RulesEngine

Page 35: SOEN 6011 Software Engineering Processes

Model-View-Control Architecture (MVC)

• MVC is an acronym for Model View Controller

• It represents a software design pattern developed at Xerox PARC in 1978 (!)

• It explains a method of separating the visual, interaction and data components.

• Very popular, used extensively in Java and other languages

Page 36: SOEN 6011 Software Engineering Processes

Model-View-Control Architecture (MVC)

Model• maintains the state and data

of the application - the XML document

View• A rendering of the XML

document

Controller• The user interface presented

to the user to manipulate the application

Page 37: SOEN 6011 Software Engineering Processes

Why use MVC

• Makes it very easy to have multiple different displays of the same information.

• For example: a graph and a table could both display and edit the same data.

• Essentially provides greater control over the UI and it’s behaviour.

Page 38: SOEN 6011 Software Engineering Processes

MVC Model

• The “Model” contains the data

• Has methods to access and possibly update it’s contents.

• Often, it implements an interface which defines the allowed model interactions.

• Implementing an interface enables models to be pulled out and replaced without programming changes.

Page 39: SOEN 6011 Software Engineering Processes

MVC Controller

• Users interact with the controller.

• It interprets mouse movement, clicks, keystrokes, etc

• Communicates those activities to the model – eg: delete row, insert row, etc

• It’s interaction with the model indirectly causes the View(s) to update

Page 40: SOEN 6011 Software Engineering Processes

MVC View

• The View provides a visual representation of the model.

• There can be multiple views displaying the model at any one time.

• For example, a companies finances over time could be represented as a table and a graph.

• These are just two different views of the same data.

• When the model is updated, all Views are informed and given a chance to update themselves.

Page 41: SOEN 6011 Software Engineering Processes

Jacobson’s Objectory Design Objects

Page 42: SOEN 6011 Software Engineering Processes

Jacobson’s Objectory Design Objects

Robustness model has

• Entity objects

• Boundary (interface objects)

• Control objects

Essentially UML collaboration (communication) diagram

Page 43: SOEN 6011 Software Engineering Processes

Jacobson’s Robustness Analysis Bridges Analysis-Design Gap

Page 44: SOEN 6011 Software Engineering Processes

PATTERN: Controller

• What object in the domain (or application coordination layer) receives requests for work from the UI layer?

???

Presentation

ApplicationLogic

Video Store

Record Rental

Video ID

...

...

...

... ...

Clerk

rent(videoID)

Now what happens?

Page 45: SOEN 6011 Software Engineering Processes

GRASP: Controller

• Who handles a system event?– E.g. “List Movies”

• Main choices: assign to a design entity representing– Overall system,

or subsystem (façade controller).– A Use Case scenario

(often named, e.g. ListMovieHandler).

Page 46: SOEN 6011 Software Engineering Processes

PATTERN: Controller (Larman 17.13)

Problem: What object in the domain (or application coordination layer) receives requests for work from the UI layer?

System operations (see SSD): major input events to the system

The controller is the first object beyond the UI layer that is responsible for receiving or handling a system operations message.

Note that UI objects delegate system operation request to a controller.

Page 47: SOEN 6011 Software Engineering Processes

PATTERN: Controller (Larman 17.13)

Solution: Assign the responsibility to a class representing one of the following choices:

• A façade controller, which represents1. the overall system

2. A root object

3. A device that the software is running within, or

4. A major subsystem

• A use case or session controller which represents a use case scenario in which the system operation occurs

Page 48: SOEN 6011 Software Engineering Processes

Fig. 17.21

Which class of object should be responsible for receiving this system event message?

It is sometimes called the controller or coordinator. It does not normally do the work, but delegates it to other objects.

The controller is a kind of "facade" onto the domain layer from the interface layer.

actionPerformed( actionEvent )

: ???

: Cashier

:SaleJFrame

presses button

enterItem(itemID, qty)

UI Layer

Domain Layer

system operation message

Page 49: SOEN 6011 Software Engineering Processes

Dom

ain

Data

Sou

rce

Table Data Gateway

Transaction Script Domain Model

Data MapperRow Data Gateway

Active Record

Front Controller

Template View

Transform View

Page Controller

Pres

enta

tion Data Source Patterns

Page 50: SOEN 6011 Software Engineering Processes

Row Data Gateway

• An object that acts as a single record in the data source– There is one instance per row

• Fowler RDG combines two rolesClass …Finder with find(id):Gateway method

which returns the ‘object’

Class …Gateway which is the ‘object’

• Our PersGradeRDG (next slide) combines

Page 51: SOEN 6011 Software Engineering Processes

Row Data Gateway

PersGradeRDG- name : String

- grade : int

+ PersGradeRDG(name, grade)

+ find(name) : PersGradeRDG

+ insert() : void

+ update() : void

+ delete() : void

+ … getters and setters …

Page 52: SOEN 6011 Software Engineering Processes

Row Data Gateway: Find Code

Page 53: SOEN 6011 Software Engineering Processes

Row Data Gateway

• Code sample for Fowler’s PersonRDG

• Note ‘find’ method is static– it is class method

Page 54: SOEN 6011 Software Engineering Processes

GetByLastName Example

Simple web application toInput a student’s last name

Fetch database record

Output student’s full name

Page 55: SOEN 6011 Software Engineering Processes

GetByLastName

Will look atRow Data Gateway

PageController

Transaction Script

Page 56: SOEN 6011 Software Engineering Processes

Row Data Gateway

• StudInfoRDG– Represents record in DB of student

• StudInfoFinder– Finds student record based on lastName– Returns the StudInfoRDG– Locates DB using DBRegistry

Page 57: SOEN 6011 Software Engineering Processes

Dom

ain

Data

Sou

rce

Table Data Gateway

Transaction Script Domain Model

Data MapperRow Data Gateway

Front Controller

Template View

Transform View

Page Controller

Pres

enta

tion

Active Record

Enterprise Application Patterns

Page 58: SOEN 6011 Software Engineering Processes

Transaction Script

Fowler: A TS organizes the business logic primarily as a single procedure where each procedure handles a single request from the presentation.

The TS may make calls directly to the DB or through a thin DB wrapper.

Think of a script for:a use case or business transaction.

Implementation can be– shared among subroutines.– Subroutines can be used by more than one script

Page 59: SOEN 6011 Software Engineering Processes

Transaction Script

• … is essentially a procedure that takes the– input from the presentation,– processes it with validations and calculations,– stores data in the database,– (invokes any operations from other systems, and)– replies with more data to the presentation perhaps

doing more calculation to help organize and format the reply data.

(Fowler)

Page 60: SOEN 6011 Software Engineering Processes

GetByLastName

Will look atRow Data Gateway

PageController

Transaction Script

Page 61: SOEN 6011 Software Engineering Processes

Do-it-all Transaction Script

A TS that does all the work itselfWithout a Finder

Without a RDG

Directly calls DB

Page 62: SOEN 6011 Software Engineering Processes

Do-it-all Servlet or Script, Class

public class DoItAll extends javax.servlet.http.HttpServlet

{protected void doGet(

HttpServletRequest request,HttpServletResponse response)throws ... //

{…}

}

Page 63: SOEN 6011 Software Engineering Processes

Do-it-all Transaction Script, doGet()

String lastName = request.getParameter(“…"); Connection dbc = DbRegistry.getDbConnection();String findSql = "SELECT * from … where LastName = ?”;PreparedStatement dbQuery = dbc.prepareStatement(findSql);

dbQuery.setString(1, lastName);ResultSet rs = dbQuery.executeQuery();rs.next();String firstName = rs.getString("FirstName");lastName = lastName.toUpperCase();PrintWriter out = response.getWriter();response.setContentType("text/html");out.println("<h1>Hello "+firstName+" "+lastName+"</h1>");

Page 64: SOEN 6011 Software Engineering Processes

Dom

ain

Data

Sou

rce

Table Data Gateway

Transaction Script Domain Model

Data MapperRow Data Gateway

Active Record

Front Controller

Template View

Transform View

Page Controller

Pres

enta

tion Controller Patterns

Page 65: SOEN 6011 Software Engineering Processes

Page Controller

Fowler:A Page Controller is an object that handles a

request for a specific page or action on a web site.

There is one input controller for each logical page of the web site.

Page Controller handles the http get and post

Decides which model and view to use

Page 66: SOEN 6011 Software Engineering Processes

Page Controller

Responsibilities:– Decode the URL, extract any form data, decide action– Create and invoke any model objects

• All relevant data from the html request should be passed to the model, so the model does not need any connection to html request

– Determine which view should display the result page• Forward model information to it

Helper objects can be created/used to perform tasks that are shared

Page 67: SOEN 6011 Software Engineering Processes

Page ControllerFowler Example:

display info about a recording artist– ActionServlet implements common ‘forward’ task– ArtistController implements doGet()

• Checks artist name is ok• Creates a new ArtistHelper object with Artist as attribute• Adds helper information to html request• Forwards request to Artist.jsp

– Artist.jsp is a TemplateView which gets information to display from helper object (which it gets from request)

Page 68: SOEN 6011 Software Engineering Processes

Page Controller

Page 69: SOEN 6011 Software Engineering Processes

GetByLastName

Will look atRow Data Gateway

PageController

Transaction Script

Page 70: SOEN 6011 Software Engineering Processes

Page ControllerSOEN EA sample:display info about a student

– PageController implements doGet()• Delegates to transaction script

Note:does not follow Fowler’s use of .jspdelegates rather than forwardsno explicit helper object

(really StudInfoRDG is helper)

Page 71: SOEN 6011 Software Engineering Processes

Dom

ain

Data

Sou

rce

Transaction Script

Active Record

Front Controller

Template ViewPage Controller

Pres

enta

tion

Domain Logic Patterns

Domain Model

Data Mapper

Transform View

Table Data Gateway

Table Module

Row Data Gateway

Page 72: SOEN 6011 Software Engineering Processes

Domain Logic (Layer)

• “… also referred to as business logic. … It involves calculations based on inputs and stored data, validation of any data that comes in from the presentation, and figuring out exactly what data source logic to dispatch …” p.20

Page 73: SOEN 6011 Software Engineering Processes

Pure Domain Logic Patterns

• Two main alternatives:– Transaction Script– Domain Model

Page 74: SOEN 6011 Software Engineering Processes

Hybrid Domain Logic

• Hybrid (Domain & Data Source) alternatives:– Active Record – Table Module

• To be discussed a little later.

• For now, focus on the pure Domain Logic patterns.

Page 75: SOEN 6011 Software Engineering Processes

Choosing Between TS & DM

• Application is simple access to data sources Transaction Script, (or Active Record, Table

Module)

• Significant amount of business logic Domain Model

• TS is simpler:– Easier and quicker to develop and maintain.– But can lead to duplication in logic / code.

Page 76: SOEN 6011 Software Engineering Processes

Domain Model (EA Pattern)

Fowler: An object model of the domain that incorporates both behaviour and data.

A DM creates a web of interconnected objects, where each object represents some meaningful individual, whether as large as a corporation or as small as a single line in an order form.

Page 77: SOEN 6011 Software Engineering Processes

Domain Model (EA Pattern)

• Realization (via design classes) of UML Domain Model (conceptual classes).– E.g. person, book, shopping cart, task, sales line item,

• Domain Model classes contain– Logic for handling validations and calculations.

• E.g. a shipment object– calculate the shipping charge for a delivery.

• Can still have routines for actions (e.g. checkout)– but they quickly delegate to method in Domain Model.

Page 78: SOEN 6011 Software Engineering Processes

Hybrid Data Source Patterns

• Active Record = RDG + Domain Logic.

• Table Module ≈ TDG + Domain Logic.– TDG like module that processes ResultSets.

Page 79: SOEN 6011 Software Engineering Processes

Active RecordFowler: An object that wraps a row in a database

table or view, encapsulates the database access, and holds domain logic on that data.

An AR object carries both data and behaviour.

The essence of an AR is a Domain Model in which the classes match very closely the record structure of the underlying database.

Page 80: SOEN 6011 Software Engineering Processes

Active Record (Row Data Gateway)

PersGradeARname : String

grade : int

PersGradeAR(name, g)

find(name)

… // like RDG

// Can also have domain logic

getRank()

Page 81: SOEN 6011 Software Engineering Processes

Data Mappers

• Acts as an intermediary between Domain Models and the database.

• Allows Domain Models and Data Source classes to be independent of each other

• E.g. …

Page 82: SOEN 6011 Software Engineering Processes

Data Mapper Example (Tasks)

«Domain Model»Task

- id : long- isDone : boolean- title : String

+ Task ( )+ Task ( [in] aTitle : String )+ getId ( ) : long+ getTitle ( ) : String+ isDone ( ) : boolean+ setId ( [in] anId : long ) : void+ setIsDone ( [in] b : boolean ) : void

TaskMapper

- TaskMapper ( )+ find ( [in] id : long ) : Task+ findAll ( ) : List+ insert ( [in] task : Task ) : void+ update ( [in] task : Task ) : void+ delete ( [in] task : Task ) : void

DBMS

Page 83: SOEN 6011 Software Engineering Processes

Data Mapper Layer …

• Can either– Access the database itself, or– Make use of a Table Data Gateway.

• Does not contain Domain Logic.

• When it uses a TDG, the Data Mapper can be placed in the (lower) Domain layer.

• E.g. …

Page 84: SOEN 6011 Software Engineering Processes

Dom

ain

Data

Sou

rce

Table Data Gateway

Transaction Script Domain Model

Data Mapper

Row Data Gateway

Front Controller

Template View

Transform View

Page Controller

Pres

enta

tion

Active Record

Enterprise Application Patterns (v1.3)

Table Module


Recommended