zoukankan      html  css  js  c++  java
  • 软件工程 实践者的研究方法 第16章答案

    Problem:

    Discuss the three “parts” of a design pattern and provide a concrete example of each from some field other than software.

    Answer:

    A design pattern can be characterized as “a three-part rule which expresses a relation between a certain context, a problem, and a solution”.

    • The context allows the reader to understand the environment in which the problem resides and what solution might be appropriate within that environment.

    • A set of requirements, including limitations and constraints, acts as a system of forces that influences how the problem can be interpreted within its context and how the solution can be effectively applied.

    Take an example in which a person must travel between and .

    • In this context, travel will occur within a developed country (the ), using an existing transportation infrastructure (e.g., roads, airlines, railways).

    The system of forces that will affect the way in which the travel problem is solved will include: how quickly the person wants to get from New York to Los Angeles, whether the trip will include site-seeing or stopovers, how much money the person can spend, whether the trip is intended to accomplish a specific purpose, and the personal vehicles the person has at her disposal.

    • Given these forces, the problem (traveling from to ) can be better defined. For example, investigation (requirements gathering) indicates that the person has very little money, owns only a bicycle, wants to make the trip to raise money for her favorite charity and has plenty of time to spare.

    The solution to the problem, given the context and the system of forces, might be a cross-country bike trip. If the forces were different, another solution might be more appropriate.

    Problem:

    What is the difference between a nongenerative and a generative pattern?

    Answer:

    4633-12-2P SA: 9420

    SR: 6376

    A generative pattern describes the problem, a context, and forces, but it also describes a pragmatic solution to the problem, where as a non-generative pattern describes a context and a problem but it does not provide any clear-cut solution.

    Problem:

    How do architectural patterns differ from component patterns?

    Answer:

    4633-12-3P SA: 9420

    SR: 6376

    • The architectural patterns describe broad-based design problems that are solved using a structural approach.

    • The component patterns (also referred to as design patterns) address problems associated with the development of subsystems and components, the manner in which they communicate with one another, and their placement within a larger architecture.

    • In the terms of the level of granularity, architectural patterns level of abstraction will typically relate to patterns that define the overall structure of the WebApp, indicate the relationships among different components or increments, and define the rules for specifying relationships among the elements of the architecture.

    • Component patterns level of abstraction relates to individual small-scale elements of a WebApp.

    What is a framework and how does it differ from a pattern? What is an idiom and how does it differ from a pattern?

    Answer:

    4633-12-4P SA: 9420

    SR: 6376

    Framework: A framework is a reusable “mini-architecture” that serves as a foundation from which other design patterns can be applied.

    Differences between a framework and a pattern:

    • Patterns themselves may not be sufficient to develop a complete design, but a framework is necessary to provide implementation specific skeletal infrastructure for design work.

    • A framework is not an architectural pattern, but rather a skeleton with a collection of “plug points” that enable it to be adapted to a specific problem domain.

    • Design patterns are more abstract than frameworks: Frame works can be embodied in code, it’s executed and reused directly but only examples of patterns can be embodied in code.

    • Design patterns are smaller architectural elements than frameworks

    • Design patterns are less specialized than frameworks. Frameworks always have a particular application domain.

    • In contrast, design patterns can be used in nearly any kind of application.

    Idiom: An idiom describes how to implement all or part of a specific algorithm or data structure for a software component within the context of a specific programming language.

    Differences between an idiom and a pattern:

    • Architectural patterns describe broad based design problems that are solved using a structural approach.

    • Data patterns describe frequent data oriented problems.

    • Component patterns address problems associated with the development of subsystems and components.

    • Interface design patterns describe common user interface problems.

    • WebApp patterns address a problem set that is encountered when building WebApps and often incorporates many of the other patterns categories.

    • But idioms describe programming language-specific implementation detail for all or part of a specific algorithm or data structure.

    • Finally, Idioms relate to code and patterns relate to design.

    • Idioms are smaller and language-specific and patterns are big idioms.

    Using the design pattern template presented in Section 16.1.3, develop a complete pattern description for a pattern suggested by your instructor.

    Answer:

    Let us consider a pattern named as model-view-controller. In a model-view-controller, we have three major objects – model, view, and controller.

    Following is the pattern description for a model-view-controller.

    Pattern name: model-view-controller

    Problem: This pattern addresses the problem of high coupling and interdependencies among various classes. The main objective is to decouple the view of the data from the actual data processing so that the same model can be used for various views.

    Motivation: High coupling makes classes difficult or impossible to reuse because they depend on so many other classes. Even if a small change is to be made then the entire system may have to be changed.

    Context: The problem comes mainly in the computer systems where data is retrieved from a data store and displayed to the user. After the user changes the data, the system stores the updates in the data store. The problem arises in the cases where the two objects are combined and coded together to reduce the amount of coding and to improve application performance. The problem that may arise usually is that the user interface tends to change much more frequently than the data storage system. So the data storage system should also be changed even if it is not needed.

    Forces: Following are the forces that impose to find a solution to the problem.

    • User interface logic tends to change more frequently than business logic (data store), especially in Web-based applications. If presentation code and business logic are combined in a single object, you have to modify an object containing business logic every time you change the user interface. This is likely to introduce errors and require the retesting of all business logic after every minimal user interface change.

    • Designing a User interface needs some logic and a data store needs some logic. So getting a person who is expert in both the skills is difficult.

    • User interface code tends to be more device-dependent than business logic

    • Supporting multiple types of views and interactions should not impact the components that provide the core functionality of the enterprise application

    Solution: The Model-View-Controller (MVC) pattern separates the modeling of the domain, the presentation, and the actions. Such separation allows multiple views to share the same enterprise data model, which makes supporting multiple clients easier to implement, test, and maintain.

    Intent:

    The MVC pattern contains three major domains – model, view, and controller. Their functions are,

    • Model – Model is responsible for actual data processing, like database connection, querying database, implementing business rules etc. It feeds data to the view

    • View - The view manages the display of information. It is responsible for look and feel, formatting etc. It accesses enterprise data through the model and specifies how that data should be presented

    • Controller - The controller translates interactions with the view into actions to be performed by the model.

    Collaborations: JavaServer Pages (JSP) contributes to render the view, Servlet as the controller, and Enterprise JavaBeans (EJB) serves as the model

    Consequences: while implementing the pattern, the following potential trade-offs must be considered.

    • Re-use of Model components. The components in the pattern must be designed, so that they can be used in various views. It must be taken care while designing.

    • Easier support for new types of clients. The pattern should be compatible to support a new type of client.

    Implementation: .NET framework can be used to implement the MVC design pattern.

    Known uses: it supports multiple views. For example, multiple pages in a Web application may use the same model objects.

    It accommodates changes. Users may prefer different colors, fonts, screen layouts, and levels of support for new devices such as cell phones or PDAs. Because the model does not depend on the views, adding new types of views to the system generally does not affect the model.

    This makes the application extensible and scalable.

    Related patterns:

    Observer – This pattern is often mentioned in conjunction with MVC due to the need to keep the views and the associated model synchronized

    Problem:

    Develop a skeletal pattern language for a sport with which you are familiar. You can begin by addressing the context, the system of forces, and the broad problems that a coach and team must solve. You need only specify pattern names and provide a one-sentence description for each pattern.

    Answer: Problem:

    Find five patterns repositories and present an abbreviated description of the types of patterns contained in each.

    Answer:

    Some of the types of patterns that are obtained from the pattern repositories are:

    Anti pattern: An anti pattern is a pattern that informs how to go from a problem to a bad solution.

    Messaging design pattern: It is allows the exchange of information (i.e. messages) between applications and components.

    Security pattern: It is a well-understood solution to a recurring information security problem.

    Design pattern: It is provides a scheme for refining the subsystems or components of a software system, or the relationships between them.

    Architectural pattern: An architectural pattern expresses a fundamental structural organization or schema for software systems.

    When Christopher Alexander says “good design cannot be achieved simply by adding together performing parts,” what do you think he means?

    Answer:

    Christopher Alexander says “good design cannot be achieved simply by adding together performing parts”. He means that, the a software design will not become good by simply adding all the well performing parts, but it is something more than that. It needs a sequence of activities to be done.

    Good design begins by considering context. As context is evaluated, you extract a hierarchy of problems that must be solved. Some of these problems will be global in nature, while others will address specific features and functions of the software. All will be affected by a system of forces that will influence the nature of the solution that is proposed.

    Using the pattern-based design tasks noted in Section 16.2.3, develop a skeletal design for the “interior design system” described in Section 15.3.2.

    Answer:

    A skeleton design for the interior design system described in section 15.3.2 of the book, using the pattern based design tasks presented in section 16.2.3 is given as:-

    1. Make a problem hierarchy by examining the requirements:

    In this case, the main problem is ‘How does an interior designer decide where to put furniture in an office room.’ Construct a problem hierarchy as:

    • What furniture does the office have?

    • What theme has the office owner selected? if any, decide on the fabric and material accordingly.

    • Check from where the light enters the office?

    • Check the views in window. If it is good the interior should draw attention to it?

    • Where is the flow of movement in the office? Keep that area vacant.

    • Does the designer need to buy more new items? If yes, select their fabric and material according to a theme.

    • Use a computer aided design system to

    o Sketch the floor plan of the office including windows, door and wall dimensions.

    o Draw the furniture layout.

    o Draw a 3D picture of the room with furniture placed and show it to client.

    • Has the interior design been accepted? If yes, implement it.

    2. Check if a pattern language exists for problem domain.

    A pattern language has been designed for interior designer by Christopher Alexander. He has written a book called ‘A pattern language’.

    3. Check if one or more architectural patterns exist for the problem.

    Yes, they are available online (with some fees) and in the above book also. The rest of the questions cannot be discussed as the writer does not have access to the book or the online resources.

    Build a pattern-organizing table for the patterns you used in Problem 16.9.

    Answer: Problem:

    Using the design pattern template presented in Section 16.1.3, develop a complete pattern description for the Kitchen pattern mentioned in Section 16.3.

    Answer:

    Pattern description for the Kitchen pattern cited in section 16.3 of the book, using the design pattern template shown in section 16.1.3 is given as:-

    Pattern name

    Kitchen pattern

    Problem

    To store and prepare food, the resources required to prepare food.

    Motivation

    Problem associated with lighting, wall switches, countertops etc.

    Context

    The kitchen itself and the appliances, resources already available with the client

    Forces

    The monetary and time resources the client is willing to spend on the project.

    Solution

    • List the resources, furniture and appliances the client already has

    • Check from where the light enters the kitchen.

    • Keep an eye on the flow of movement in the kitchen. Keep that area vacant.

    • If some items are to be bought select as per requirement.

    • Use a computer aided design system to

    o Sketch the floor plan of the kitchen including, windows, door and wall dimension

    o Draw the resources, appliances, and furniture layout.

    o Draw a 3D picture of the kitchen with resources placed and show it to client.

    • On acceptance of the interior design, implement it.

    Intent

    The pattern makes the kitchen functional, convenient and looks aesthetically pleasing and the client is happy with the interiors of the kitchen.

    collaborations

    If the client needs to buy new appliances, do it.

    Related patterns

    In the book called ‘A pattern language’.

    The gang of four [Gam95] have proposed a variety of component patterns that are applicable to object-oriented systems. Select one (these are available on the Web) and discuss it.

    Answer:

    The Gang of Four is a team of four people - Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. These people were nicknamed the "Gang of Four"

    The Gang of Four describes 23 design patterns. These patterns are generally considered the foundation for all other patterns. They are categorized in three groups: Creational, Structural, and Behavioral.

    Factory method pattern:

    “Factory method pattern” is one among the patterns proposed by Gang of four. It comes under the category of creational patterns. This is one that returns an instance of one of several possible classes depending on the data provided to it. It deals with the situations where at runtime one of several similar classes must be created. Usually all of the classes it returns have a common parent class and common methods, but each of them performs a task differently and is optimized for different kinds of data.Factory Methods are routinely specified by an architectural framework, and then implemented by the user of the framework. The Factory Method defines an interface for creating objects, but lets subclasses decide which classes to instantiate

    Factory method in UML:

    Following is the UML diagram of a factory method.

    4633-12-12p-i1.png

    Usage:

    The Factory patterns can be used in following cases:1. When a class does not know which class of objects it must create.2. A class specifies its sub-classes to specify which objects to create.

    Find three patterns repositories for user-interface patterns. Select one pattern from each and present an abbreviated description of it.

    Answer:

    The three pattern repositories considered are:

    • Yahoo design pattern library

    • Welie pattern library

    • Quince patterns library

    The patterns from each repository are:

    1. Left navigation: A left navigation bar provides quick access to categorized content in a horizontally compact display space

    2. Wizard: Takes the user through a complex task one step at a time, providing guidance for the completion of the task through a series of simple window displays.

    3. Bread Crumbs: This pattern provides a full navigation path when the user is working with a complex hierarchy of pages or display screens.

    Find three patterns repositories for WebApp patterns. Select one pattern from each and present an abbreviated description of it.

    Answer:

    The three pattern repositories considered for WebApp patterns are:

    • Security patterns library

    • Nowires

    The patterns from each repository are:

    1. Privacy-Aware Network Client Pattern: This pattern provides a way to make a user of a network site aware of the privacy policies followed by that site

    2. Input validation: This pattern validates input from the client.

    3. Account Lockout: This pattern protects customer accounts from automated password guessing attacks.

    Find three patterns repositories for mobile patterns. Select one pattern from each and present an abbreviated description of it.

    Answer:

    A few pattern repositories for mobile are:-

    1. Web site name: pattern

    One of the patterns on the site is for calculators and converters. The calculator can be a simple one with facility to perform arithmatic operations or a scientific one which also performs trignomatric, calculus operations.

    The input is limited to the numbers and operations on the screen. Pressing other keys on the smartphone will not have any effect on the application.

    Here is a snapshot:-

    Picture 1

    2. Web site name: patternry

    One of the pattern on the site is for input prompt on on a mobile. It asks user for text input. Text will be validated against some criteria for the input ( @ and .com for an email id etc.) and processed when a graphic indicator ( a submit or search button). Below is a snapshot of the same:-

    Picture 3

    3. Web site name: zurb.com/patterntap

    One of the pattern on the site is infographic from one company on a mobile. It displays flowchart and text explanation for the objects in the flowchart.

    Picture 5


    Solution: CHAPTER16: PATTERN-BASED DESIGN

    16.1 A design pattern can be characterized as a three-part rule which expresses a relation between a certain context, a problem, and a solution. Context allows the reader to understand the environment in which the problem resides and what solution might be appropriate within that environment. A set of requirements, including limitations and constraints, acts as a system of forces that influences how the problem can be interpreted within its context and how the solution can be effectively applied.

    16.2 Non-generative - describes a context and a problem but it does not provide any clear-cut solution. Generative - used to “generate” an application or computer-based system whose architecture enables it to adapt to change.

    16.3 Architectural patterns - describe broad-based design problems that are solved using a structural approach. Component patterns (also referred to as design patterns) - address problems associated with the development of subsystems and components, the manner in which they communicate with one another, and their placement within a larger architecture,

    16.4 Frameworks are used to complete the design when design patterns are not detailed enough. Implementation-specific skeletal infrastructure containing plug points (hooks or slots) that enable it to be adapted to a specific problem domain Plug points allow developers to integrate problem specific classes or functionality within the skeleton. In object-oriented design a framework would be a set of cooperating classes. Design patterns are more abstract than frameworks. Design patterns are smaller architectural elements than frameworks. Design patterns are less specialized than frameworks. A framework provides an infrastructure in which patterns may reside and idioms describe programming language specific implement detail for all or part of a specific algorithm or data structure.

    16.5 Answers will vary

    16.6 Answers will vary

    16.7 Answers will vary

    16.8 Good design begins by considering context—the big picture. As context is evaluated, you extract a hierarchy of problems that must be solved. Some of these problems will be global in nature, while others will address specific features and functions of the software. All will be affected by a system of forces that will influence the nature of the solution that is proposed. Focusing on individual parts causing the designer to lose sight of the big picture and often results in a substandard design..

    16.9 Answers will vary

    16.10 Answers will vary

    16.11 Answers will vary

    16.12 Answers will vary

    16.13 Answers will vary

    16.14 Answers will vary

  • 相关阅读:
    Hadoop运行任务时一直卡在: INFO mapreduce.Job: Running job
    用easy_install時出現unknown url type: https问题
    docker的安装
    在构建Python3.6环境的docker镜像时遇到python-devel无法安装
    红帽考试
    samba服务器的搭建
    hbase0.98.9安装
    hadoop2.7.3安装
    window的socket编程设置connect连接超时
    Oracle11g用户密码密码180天(默认值)过期后的修改方法
  • 原文地址:https://www.cnblogs.com/mikecracker/p/14315507.html
Copyright © 2011-2022 走看看