Post on 22-Dec-2015
transcript
Reuse ActivitiesReuse ActivitiesSelecting Design Selecting Design
Patterns and Patterns and ComponentsComponents
Part (2)Part (2)
OutlineOutline
• Encapsulation Control Flow with the Command Pattern.
• Encapsulation Hierarchies with the Composite Design Pattern.
• Heuristics for Selecting Design Patterns.
• Identifying and Adjusting application framework.
• Problem:
We don’t want the classes responsible for recording and replaying moves to depend on specific game.
• Solution:
Using Command Design Pattern.
Match
Play()
Replay()
Move
Execute()
Execute()Execute()
ChessMoveTicTacToeMoveGameBoard
binds
*
Command Design Pattern uses specification inheritance between command class and concrete command enabling new command to be added independently from the invoker.
• Delegation is a way of making composition (for example aggregation) as powerful for reuse as inheritance.
• In Delegation two objects are involved in handling a request:– A receiving object delegates operations to its delegate. – The developer can make sure that the receiving object
does not allow the client to misuse the delegate object
Client Receiver DelegateDelegates to calls
Delegation is used between concrete commands and receivers, and between invoker and command enabling concrete command to be dynamically created, executed and stored.
Main
Encapsulation Hierarchies with the Encapsulation Hierarchies with the Composite Design Pattern.Composite Design Pattern.
Definition: A software system consists of subsystems which are either other subsystems or collection of classes
Composite: Subsystem (A software system consists of subsystems which consists of subsystems , which consists of subsystems, which...
SoftwareSystem
ClassSubsystem Children
*User
Grid layout(3,4)
Border layout
Border layout
Composite Design PatternComposite Design Pattern
Component
Move()
Resize() Composite
Move()
Resize()
Applet
window Panel
Label Button Checkbox
*
Main
Heuristics for Selecting Design Heuristics for Selecting Design Patterns.Patterns.
Using key phrases in the Requirement Analysis Document (RAD) and System Design Document (SDD).
Heuristics box
Phrase Design Pattern
“Manufacturer independence”
“Platform independence”
Abstract factory
“Must comply with existing interface”
“Must reuse existing legacy component”
Adapter
“Must support future protocol” Bridge
“All commands should be undoable”
“All transactions should be logged”
Command
“Must support aggregate structures”
“Must allow for hierarchies of variable depth and width”
Composite
“Policy and mechanisms should be decoupled”
“Must allow different algorithms to be interchanged at runtime.”
Strategy
Main
Application Framework DefinitionApplication Framework Definition
An application framework is a reusable partial application that can be specialized to produce custom applications. Frameworks are targeted to particular technologies.
Examples of application Examples of application FrameworksFrameworks
Examples
Data processingCellular
communicationsApplication domain
FrameworkUseful to
Reusability Extensibility
Application domainknowledge
Prior effort of experienced developers
to avoid recreation and validation
By providing Hook methods
Framework classificationby position
Infrastructureframeworks
Middlewareframeworks
Enterprise applicationFrameworks
Infrastructure Middleware Enterprise application
Aim to simplify software development process. Used internally within software project
Used to integrate existing distributed application and components.
Focus on domains such as telecommunicati-ons
Are essential to create rapidly high quality software systems
Support the development of end user applications.
FrameworkClassificationby techniques
WhiteboxFramework
BlackboxFramework
Whitebox• Rely on inheritance and
dynamic building for extensibility.
• Existing functionality is extended by subclassing framework base classes and overriding predefined hook methods.
Blackbox• Support extensibility by
defining interfaces for components that con be plugged into the framework.
• Existing functionality is reused by defining components that conform to particular interface.
• Require intimate knowledge of the framework’s internal structure.
• Produce systems that are tightly coupled to the specific details of the framework’s inheritance hierarchies, thus change in framework require recompilation of application.
• Easier to use because of delegation.
• More difficult to develop because require definition of interfaces and hooks.
• Easier to extend and reconfigure dynamically.
Design patterns versus frameworksDesign patterns versus frameworks
Design pattern
Focus on reuse of abstract designs and small collections of cooperating classes.
Can be viewed more as building blocks of frameworks.
Framework
Focus on reuse of concrete designs, algorithms and implementations in a particular programming language.
Focus on particular application domain.
Class Libraries versus FrameworksClass Libraries versus Frameworks
Class librariesLess domain specific and
provide smaller scope of reuse. eg: classes for strings, complex numbers, arrays and bitsets.
Passive: don’t implement constrain the control flow.
FrameworksCooperate to provide a
reusable architectural skeleton for a family of related applications.
Active: control the flow of control within an application.
Components versus FrameworksComponents versus FrameworksComponents
Self contained instances of classes that are plugged together to form complete applications.
It is a blackbox that defines a cohesive set of operations that can be used solely with knowledge of the syntax and semantics of its interfaces.
Less tightly coupled and can be reused on the binary code level.
Application don’t always have to be recompiled when components change.
component interface provides a façade pattern for the internal class structure of the framework.
Can be plugged into blackbox framework.Used to simplify the development of end user
application software.
FrameworksCan be used to
develop components.
Used to simplify the development of infrastructure and middleware software.
Components are often plugged into blackbox frameworks.
Example: Framework for Building Example: Framework for Building Web ApplicationsWeb Applications
WebBrowser
RelationalDatabase
StaticHTML
WOAdaptorWebServer
WoRequest Template
WebObjectsApplication
WORequest
EOF
Thanks for your attention