Click here to load reader

SOEN 343 Software Design

  • View
    34

  • Download
    3

Embed Size (px)

DESCRIPTION

SOEN 343 Software Design. Section H Fall 2006 Dr Greg Butler http://www.cs.concordia.ca/~gregb/home/soen343h-f06.html. Outline. Week 9 lectures: Evaluate Good Design Page Controller and Front Controller Note Command Pattern Web EA Do-It-All TS Re-design GRASP Principles - PowerPoint PPT Presentation

Text of SOEN 343 Software Design

  • SOEN 343Software DesignSection H Fall 2006Dr Greg Butlerhttp://www.cs.concordia.ca/~gregb/home/soen343h-f06.html

  • OutlineWeek 9 lectures: Evaluate Good Design

    Page Controller and Front ControllerNote Command PatternWeb EA Do-It-All TS Re-design

    GRASP PrinciplesPure FabricationIndirection

  • Recall the Greeting EAA single servlet which offers the greeting Hello.We refactored it, offering two alternative designs.

    #doGet(in req, in resp)

    GreetingServlet

  • Review QuestionOn a blank sheet of paper Provide three class diagrams corresponding to the three design solutions of the Greeting EA.

  • Evaluating a DesignWhich is a better design?What is a good design?

  • What is a good design?Satisfies user needs, requirements.Reveals intent.Is a simple as possible.Minimizes cost of likely changes.And High cohesion.Low coupling.

  • Greeting EA Evolution What if Support a personalized greeting.Change look of output (e.g. bold the name).Get full name from db.

  • Comparing Design Solutions

  • GRASP: ControllerWho handles a system event?E.g. List MoviesMain choices: assign to a design entity representingOverall system, or subsystem (faade controller).A Use Case scenario (often named, e.g. ListMovieHandler).

  • GRASP: ControllerWho handles a system event?E.g. List MoviesMain choices: assign to a design entity representingOverall system, or subsystem (faade controller).A Use Case scenario (often named, e.g. ListMovieHandler).

  • Controller PatternsDomainData SourceTable Data GatewayTransaction ScriptDomain ModelData MapperRow Data GatewayFront ControllerTemplate ViewTransform ViewPage ControllerPresentationActive RecordTable ModuleData MapperTable Data Gateway

  • Page Controller (done)

  • Front ControllerFowler: A controller that handles all requests for a web site.

    The Front Controller consolidates all request handling by channeling requests through a single handler object. This object can carry out common behaviour which can be modified at runtime with decorators. This handler then dispatches to command objects for behaviour particular to a request.

  • Front ControllerGoF design pattern: CommandUse a Command object to encapsulate the steps that are executed by a command.Command::doIt() executes commandAllows Command::unDoIt() etc

    GoF design pattern: DecoratorDecorator::m() adds additional behaviour, but delegates to real Object::m() for real behaviourEg, logging command execution before/after executing command

  • Page vs Front Controller Differences in URL

    Page Controllers for A1 http:/stu.cs/343A1/ViewTaskListhttp:/stu.cs/343A1/AddTaskhttp:/stu.cs/343A1/RemoveAllTasksFront Controller for A1Base URL: http:/stu.cs/343A1/frontController/frontController ?command=ViewTaskList/frontController ?command=AddTaskGrade&title=abc&

  • Front Controller

  • Front Controller

  • Front Controller (Fowler)Command (GoF) PatternsFrontCommand+ init ( )+ processRequest ( )ViewStudInfoCommand+ processRequest ( )RemoveStudentCommand+ processRequest ( )

  • Front Controller: Sequence Diagram

  • Front Controller: ProcessRequest

  • Front Controller (contd)

  • Front Controller: Advantages?

  • Web EA Redesign ExerciseRefactoring a DoItAll Servlet, let me count the ways

  • Do-it-all Servlet or ScriptDomainData SourceDo-it-all Servlet or ScriptPresentation

  • Do-it-all Servlet or Script, Classpublic class DoItAll extends javax.servlet.http.HttpServlet{protected void doGet(HttpServletRequest request,HttpServletResponse response)throws ... //{}}

  • Redesigning This ApplicationRedesign DoItAll so as to increase the class cohesion.Create new classes. Which EA patterns would you use?Distribute the doGet() method code (given on the next slide) into the new classes. Identify which lines would go into which classes.

  • 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("Hello "+firstName+" "+lastName+"");

  • Do-it-all Servlet Redesign: Separating ConcernsThe next few slides show ways in which we can separate concerns; i.e. distribute the functionality of the do-it-all script into separate classes.Combinations other than the ones shown are possible.

  • Redesigning Do-it-all (2 classes) [#1]DomainData SourceDo-it-all PresentationNote:

  • Redesigning Do-it-all (3 classes) [#3]DomainData SourceDo-it-all Presentation

  • Redesigning Do-it-all (4 classes) [#4]DomainData SourceDo-it-all Presentation

  • Redesigning Do-it-all : Adding (5 classes) [#5]DomainData SourceDo-it-all Presentation

  • Redesigning Do-it-all : Adding [#5b]DomainData SourceDo-it-all Presentation

  • Redesigning Do-it-all (5 classes) [#5c]DomainData SourceDo-it-all PresentationIs there anything wrong with this design? (Hint: consider the dependencies and the layering style.)

  • Redesigning Do-it-all (6 classes) [#6]DomainData SourceDo-it-all Presentation

  • Pure FabricationProblem: Existing objects, ie domain objects, are not appropriate to have the responsibilitySolution suggested by Information Expert not appropriateMight violate high cohesion, low coupling

    Solution: Fabricate (ie create, make up) a new object to hold the responsibility

  • GRASP: Pure FabricationAssign a highly cohesive set of responsibilities to an artificial or convenience class that does not represent a problem domain conceptsomething made up, to support high cohesion, low coupling, and reuse.

    Can you think of an example from EA?

  • GRASP: Pure FabricationDesign of objectsRepresentational decompositionBehavorial decompositionIts OK for OO software to have objects representing behaviour, ie use case, process, function, strategy, TSBut do not overdo it

    All GoF design patterns are Pure Fabrications

  • IndirectionProblem: How to assign responsibility to avoid direct coupling? How to de-couple objects?Solution: Assign responsibility to an intermediatory object to mediate between the two components

    Example: Adapter patternIntermediatory to external tax calculators

  • Fig. 25.10

    Store

    role

    records

    *

    Class

    Class

    records

    Drag the side handles to change the width of the text block.

    Drag the side handles to change the width of the text block.

    Select box and type. Control handles change width & height of box.

    Select oval andtype. Control handles change width & height of oval.

    msg()

    Sale

    entityClass

    id:Class

    1: msg()

    msg()

    msg()

    msg()

    1: msg()

    xxx

    1: msg()

    Note

    id:Class

    Note

    id:Class

    Cashier

    newClass

    the adapter acts as a level of indirection to external systems

    . . .

    xxx

    TCP socket communication

    ...

    : Sale

    :TaxMasterAdapter

    taxes = getTaxes( s )

    t = getTotal

    actor:TaxMasterSystem

  • IndirectionMost problems in computer science can be solved by another level of indirection

Search related