object-oriented frameworks n framework: architecture + implementation + hooks. n the framework...
Post on 19-Dec-2015
215 views
TRANSCRIPT
Object-Oriented FrameworksObject-Oriented Frameworks
Framework: architecture Framework: architecture + implementation + + implementation + hooks.hooks.
The framework serves as The framework serves as the basis for many the basis for many applications. Developers applications. Developers fill in the hooks to fill in the hooks to produce a new app.produce a new app.
Framework
Hooks
Framework
New Applications
Types of FrameworksTypes of Frameworks
Application frameworks - large frameworks Application frameworks - large frameworks applicable across domains that provide a wide applicable across domains that provide a wide range of services to a wide range of applications. range of services to a wide range of applications. MFC. MFC.
Domain frameworks - apply to a single domain, Domain frameworks - apply to a single domain, tend to be smaller. SEAF.tend to be smaller. SEAF.
Support frameworks - provide a small set of Support frameworks - provide a small set of underlying services which can apply across underlying services which can apply across domains. CSF.domains. CSF.
Types (2)Types (2)
Black Box frameworks - applications are built by Black Box frameworks - applications are built by plugging in components or configuring options. Easier plugging in components or configuring options. Easier to use, but less flexible.to use, but less flexible.
White Box frameworks - applications subclass or White Box frameworks - applications subclass or modify existing classes. Developers need more modify existing classes. Developers need more understanding of the workings of the frameworks. More understanding of the workings of the frameworks. More flexible, but more time to learn. flexible, but more time to learn.
Fundamental issue of ease of use vs. flexibility.Fundamental issue of ease of use vs. flexibility.
Desirable PropertiesDesirable Properties
Ease of use: easy to understand and facilitate the Ease of use: easy to understand and facilitate the development of applications.development of applications.
Extensible: new components or properties can be Extensible: new components or properties can be easily added.easily added.
Flexible: can be used for a wide variety of Flexible: can be used for a wide variety of applications.applications.
Complete: coverage of the domain.Complete: coverage of the domain.
Parts of a FrameworkParts of a Framework
FrameworkCore
FrameworkLibrary
UnusedLibraryClasses
Application Extensions
Framework Application
CSF OverviewCSF Overview
Java program that handles communication Java program that handles communication between client server or peer to peer programs between client server or peer to peer programs over a network.over a network.
Has some persistent storage capabilities.Has some persistent storage capabilities. Not a full architecture.Not a full architecture.
Communication Persistence
Communication ArchitectureCommunication Architecture
MessageHandlerCommAware
Object
Message
Data
MailBox
MailServer
Client Server
CommunicationCommunication
Objects send messages through mail servers. Objects send messages through mail servers. Developers defined the client and server objects.Developers defined the client and server objects.
Client Object
Client Object Server Object
Outbox
InboxInbox
MailServer
MailServer
Inbox
Communication (2)Communication (2) Data objects are transmitted inside the messages. Serialized Data objects are transmitted inside the messages. Serialized
on one side and rebuilt on the other, so any type of on one side and rebuilt on the other, so any type of information can be sent.information can be sent.
By default, the client and server objects invoke message By default, the client and server objects invoke message handlers every time a message arrives (just like responding handlers every time a message arrives (just like responding to a menu click).to a menu click).
Server ObjectInbox
MailServer
Message
Data
MessageHandler
Modified Three Tier Arch.Modified Three Tier Arch.
User Interface Manager
Workflow Manager
Business Rules Manager
Persistent Object Manager
Database
Client
Server
Database
Communication
Persistence
Persistence OverviewPersistence Overview
Any data object can be made a persistent data Any data object can be made a persistent data object.object.
The Persistence Manager tracks all persistent data The Persistence Manager tracks all persistent data in memory and manages how it is stored to disk.in memory and manages how it is stored to disk.
PersistentData
PersistenceManager
FileHandler
FileHandler
FileHandler
File structure
DocumentationDocumentation
The purpose of the frameworkThe purpose of the framework: a description of the : a description of the domain plus the limitations of the framework. domain plus the limitations of the framework. (General description)(General description)
The use of the framework:The use of the framework: a description of the way the a description of the way the framework is intended to be used. (Use cases, hooks, framework is intended to be used. (Use cases, hooks, examples) examples)
The design of the framework: The design of the framework: A description of the A description of the structure and behavior of the framework. (Design structure and behavior of the framework. (Design description, source code) description, source code) Should source code be Should source code be provided?provided?
Framework UseFramework Use
A framework is chosen to generally match the A framework is chosen to generally match the application requirements.application requirements.
Framework users must learn the framework before Framework users must learn the framework before they can develop an application from it.they can develop an application from it.
The application design has to conform to the The application design has to conform to the concepts provided by the framework. Users build concepts provided by the framework. Users build extensions to the framework.extensions to the framework.
Multiple frameworks can be used in a single Multiple frameworks can be used in a single application, but there may be gaps or overlap in the application, but there may be gaps or overlap in the functionality they provide.functionality they provide.
Sample Application: CSFTalkSample Application: CSFTalk
Simple text based communication between two or Simple text based communication between two or more users.more users.
A user may have several talk sessions open at the A user may have several talk sessions open at the same time.same time.
A central location keeps track of who’s connected A central location keeps track of who’s connected and available for chat, what chat sessions have and available for chat, what chat sessions have been created and who belongs to them.been created and who belongs to them.
Using CSFUsing CSF
Decide what information needs to be Decide what information needs to be communicated across the network - these become communicated across the network - these become data objects. data objects. – Strings of text (messages between users)Strings of text (messages between users)
– lists of who’s connectedlists of who’s connected
– login informationlogin information
Decide what information needs to be stored - use Decide what information needs to be stored - use persistent data objects.persistent data objects.– Conversation logConversation log
Using CSF (2)Using CSF (2)
Specify the protocol for sending that information - Specify the protocol for sending that information - produce message types for these.produce message types for these.– Connect to server, connectedConnect to server, connected
– Disconnect from serverDisconnect from server
– Start chat sessionStart chat session
– Join chat sessionJoin chat session
– End chat sessionEnd chat session
– Request who’s connected, received connected listRequest who’s connected, received connected list
– Send text message, receive text messageSend text message, receive text message
Using CSF (3)Using CSF (3)
Decide who will send and receive the Decide who will send and receive the messages - these become messages - these become CommAwareObjects. CommAwareObjects. – ClientClient– ServerServer– Chat SessionChat Session– Talk SessionTalk Session
Decide on the type of communication and Decide on the type of communication and give them mailboxes.give them mailboxes.
ClientController
ServerController
ChatSessions
TalkSessions
Inbox Outbox
CommAwareObject
Using CSF (4)Using CSF (4)
Match the CAOs to the actual messages they Match the CAOs to the actual messages they receivereceive and produce MessageHandlers for them. and produce MessageHandlers for them. These can be distinct classes, or methods of a class.These can be distinct classes, or methods of a class.– Client: connected, receive connected listClient: connected, receive connected list– Server: connect to server, disconnect, start chat session, Server: connect to server, disconnect, start chat session,
request connected listrequest connected list– Talk session: receive text message, end chat sessionTalk session: receive text message, end chat session– Chat session: send text message, end chat session, join Chat session: send text message, end chat session, join
chat sessionchat session
Message HandlersMessage Handlers
Server
Connect
Disconnect
Start Chat Session
CommAwareObject
MessageHandler
Using CSF (5)Using CSF (5)
Decide on how the programs should be connected Decide on how the programs should be connected (maintained connection vs. connectionless, (maintained connection vs. connectionless, standard application vs. applet) and choose the standard application vs. applet) and choose the appropriate MailServer.appropriate MailServer.– Talk is an application that uses the standard Talk is an application that uses the standard
connectionless mailserver.connectionless mailserver.
The choice of MailServer does not affect the other The choice of MailServer does not affect the other parts of the framework.parts of the framework.
Using CSF (6)Using CSF (6)
For any persistent data a manager must be created For any persistent data a manager must be created to save and load that data.to save and load that data.– Log file requires a log file manager.Log file requires a log file manager.
Log
PersistenceManager
Log FileManager
PersistentData
Hot Spots and HooksHot Spots and Hooks
How do you learn how to build these classes How do you learn how to build these classes and connect them together?and connect them together?
Frozen Spots: capture the commonalties Frozen Spots: capture the commonalties across applications.across applications.
Hot Spots: general areas of variability within Hot Spots: general areas of variability within a framework.a framework.
Hooks: specific ways in which a framework Hooks: specific ways in which a framework can be customized.can be customized.
Communication DesignCommunication DesignMessageHandler
CommAwareObject
Message
DataDataProxy
Address
MailBox
MailServer
Inbox
Outbox
Syncsend
DataMaster
Hot Spots
FrozenSpots
HooksHooks
How can I extend the framework to fulfill some How can I extend the framework to fulfill some requirement?requirement?– Match a requirement with one or more extensions.Match a requirement with one or more extensions.
– Mark the places at which extensions can be made in a Mark the places at which extensions can be made in a framework.framework.
– Show how those extensions can be made.Show how those extensions can be made.
Communication HooksCommunication HooksMessageHandler
CommAwareObject
Message
Data
Address
MailBox
MailServer
Inbox
Outbox
Syncsend
New CAO New MH
Create Inbox
Create Outbox
Choose Mailserver
Send Message New Data
Types of HooksTypes of Hooks The type of hooks shows in general how much The type of hooks shows in general how much
understanding of the framework is needed to make understanding of the framework is needed to make the change.the change.– OptionOption: black box changes, plug in modules, just select a : black box changes, plug in modules, just select a
pre-made component and connect it (swap mail servers).pre-made component and connect it (swap mail servers).
– Pattern: Pattern: scripted set of changes which limits the parts of scripted set of changes which limits the parts of the framework affected (create and connect mailboxes.the framework affected (create and connect mailboxes.
– Open:Open: guidelines for making a change, constraints to guidelines for making a change, constraints to consider, but mostly left open to the developer (add new consider, but mostly left open to the developer (add new types of mail servers, modify the connection protocol).types of mail servers, modify the connection protocol).
Types of Hooks (2)Types of Hooks (2)
Enable - turn on functionality. (making the Enable - turn on functionality. (making the connections necessary to send messages)connections necessary to send messages)
Disable - turn off functionality.Disable - turn off functionality. Replace - replace parts of the framework with custom Replace - replace parts of the framework with custom
parts in a well-defined way. (changing message parts in a well-defined way. (changing message dispatch)dispatch)
Augment - insert new steps into existing functionality.Augment - insert new steps into existing functionality. Add - add new parts or capabilities. (new data, new Add - add new parts or capabilities. (new data, new
methods in CommAwareObjects) methods in CommAwareObjects)
Hook DescriptionHook Description
NameName - identifies the hook. - identifies the hook. RequirementRequirement - a short description of the problem - a short description of the problem
the hook is intended for.the hook is intended for. Type - method and level of support for the change.Type - method and level of support for the change. Area - subsystem or component the hook involves.Area - subsystem or component the hook involves. ParticipantsParticipants - classes that are used by the hook. - classes that are used by the hook. Uses - other hooks used by this hook.Uses - other hooks used by this hook.
Hook Description (2)Hook Description (2)
PreconditionsPreconditions - conditions that need to be satisfied - conditions that need to be satisfied before using the hook. (Class exists, methods before using the hook. (Class exists, methods implemented, options chosen)implemented, options chosen)
ChangesChanges - the actual set of steps for using the - the actual set of steps for using the hook.hook.
PostconditionsPostconditions - conditions that should be - conditions that should be satisfied when the changes have been applied.satisfied when the changes have been applied.
CommentsComments - any additional notes about the hook. - any additional notes about the hook.
Using Hooks for CSFTalkUsing Hooks for CSFTalk
The main client and each talk session on a client The main client and each talk session on a client become become New CommAwareObjectsNew CommAwareObjects, so they can , so they can pass messages across the network.pass messages across the network.
The The Create OutboxCreate Outbox and and Create InboxCreate Inbox hooks are hooks are used for each CAO.used for each CAO.
A A New DataNew Data class TextString is created to class TextString is created to encapsulate the text being sent between each encapsulate the text being sent between each member of the chat session.member of the chat session.
The The Send MessageSend Message hook shows how to actually hook shows how to actually send text messages to members of a chat session.send text messages to members of a chat session.
Example: NewCAOExample: NewCAO Requirement: An class needs to Requirement: An class needs to
communicate across the network.communicate across the network. Participants: NewCAO, CommAwareObjectParticipants: NewCAO, CommAwareObject Uses: Handle MessageUses: Handle Message Changes:Changes:
– new subclass NewCAO of CommAwareObjectnew subclass NewCAO of CommAwareObject
– NewCAO.init extends CommAwareObject.initNewCAO.init extends CommAwareObject.init
– repeat as necessaryrepeat as necessary» fill in messagetypefill in messagetype» Handle Message[NewCAO = NewCAO, Handle Message[NewCAO = NewCAO,
message=messagetype]message=messagetype]
Client
init
CommAwareObject
init
Handle MessageHandle Message Requirement: When an object receives a message it needs to Requirement: When an object receives a message it needs to
respond to it in some way.respond to it in some way. Participants: NewCAO, message, MessageHandle, NewMHParticipants: NewCAO, message, MessageHandle, NewMH Preconditions: Preconditions:
– NewCAO subclass of CommAwareObjectNewCAO subclass of CommAwareObject
– operation NewCAO.initoperation NewCAO.init
ChangesChanges– new subclass NewMH of MessageHandlernew subclass NewMH of MessageHandler
– NewMH.handlemsg extends MessageHandler.handlemsgNewMH.handlemsg extends MessageHandler.handlemsg
– NewCAO.init -> NewCAO.registerHandler(message, NewMH)NewCAO.init -> NewCAO.registerHandler(message, NewMH)
OutcomeOutcome
Client
init
CommAwareObject
init
MessageHandler
handleMsg
Disconnect
handleMsg
ChatRequest
handleMsg
CSFTalk DiagramCSFTalk Diagram
Client Server
ChatSessions
TalkSessions
TalkWindows
MainWindow
ClientList
TextString
From the frameworkClient
List Proxy
TextString
Multiple FrameworksMultiple Frameworks
Framework gap: Since talk windows have to derive Framework gap: Since talk windows have to derive from a UI class, they cannot also derive from from a UI class, they cannot also derive from CommAwareObject. Therefore, they can’t send or CommAwareObject. Therefore, they can’t send or receive messages. There’s a gap.receive messages. There’s a gap.– Solution: Create classes to bridge the gap. In this case, Solution: Create classes to bridge the gap. In this case,
TalkSession, derived from CAO, interacts with TalkSession, derived from CAO, interacts with TalkWindow.TalkWindow.
Framework overlap: Overlaps in functionality Framework overlap: Overlaps in functionality between two frameworks require removing or not between two frameworks require removing or not using part of one of the frameworks.using part of one of the frameworks.
Framework DesignFramework Design
Frameworks differ from applicationsFrameworks differ from applications– the level of abstraction is different as frameworks the level of abstraction is different as frameworks
provide a solution for a family of related problems, provide a solution for a family of related problems, rather than a single one.rather than a single one.
– to accommodate the family of problems, the framework to accommodate the family of problems, the framework is incomplete, incorporating hot spots and hooks to is incomplete, incorporating hot spots and hooks to allow customizationallow customization
Frameworks must be designed for flexibility, Frameworks must be designed for flexibility, extensibility, completeness and ease of use.extensibility, completeness and ease of use.
Frameworks Design (2)Frameworks Design (2)
Small teams or individual developers Small teams or individual developers recommended.recommended.
Build small flexible frameworks.Build small flexible frameworks. Frameworks should be developed from Frameworks should be developed from
‘scratch.’‘scratch.’ Hooks should be considered throughout the Hooks should be considered throughout the
design process.design process.
Iterative ApproachIterative Approach
Determine the scope of the framework.Determine the scope of the framework. Identify key abstractions.Identify key abstractions. Identify hot spots.Identify hot spots. Design and implement.Design and implement. Test.Test. Refine the framework.Refine the framework.
Key AbstractionsKey Abstractions
To find:To find:– examine existing applications, or even build an examine existing applications, or even build an
application to gain expertiseapplication to gain expertise– develop scenariosdevelop scenarios
AbstractionsAbstractions– network communicationnetwork communication– how data is representedhow data is represented– means of handling that datameans of handling that data
Hot SpotsHot Spots
Examining existing applications will show Examining existing applications will show which aspects change from application to which aspects change from application to application and which remain constant.application and which remain constant.
Hot SpotsHot Spots– clients and servers varyclients and servers vary– the data sent variesthe data sent varies– means of handling that data variesmeans of handling that data varies
Design and ImplementationDesign and Implementation
Abstractions can be difficult to design Abstractions can be difficult to design properly.properly.
Specific hooks for each hot spot can be Specific hooks for each hot spot can be designed.designed.
There are trade-offs between ease of use There are trade-offs between ease of use and flexibility.and flexibility.
Designing CSFDesigning CSF
AbstractionsAbstractions– network communicationnetwork communication - mailboxes with addresses - mailboxes with addresses
transmit messages through mailserverstransmit messages through mailservers – data data - Data class that can contain any kind of - Data class that can contain any kind of
informationinformation
– handling messages handling messages - MessageHandlers are - MessageHandlers are automatically invoked whenever a message is received. automatically invoked whenever a message is received. (However, for flexibility, the mechanism can be (However, for flexibility, the mechanism can be overriden).overriden).
Designing CSF (2)Designing CSF (2)
Hot SpotsHot Spots– clients and servers varyclients and servers vary - New CommAwareObject - New CommAwareObject
HookHook
– data sent variesdata sent varies - New Data Hook - New Data Hook
– means of handling the data variesmeans of handling the data varies - New - New MessageHandler HookMessageHandler Hook
Design TipsDesign Tips• reduce the number of classes and methods users have to override
• simplify the interaction between the framework and the application extensions
• isolate platform dependent code
• do as much as possible within the framework
• factor code so that users can override limiting assumptions
• provide notification hooks so that users can react to important state changes
• consolidate similar functionality into a single abstraction
• break down larger abstractions into smaller ones with greater flexibility
• implement each key variation of an abstraction as a class
• use composition rather than inheritance
TestingTesting
Any defects in the framework will be passed on Any defects in the framework will be passed on to all applications.to all applications.
Two types of testing:Two types of testing:– A framework can be tested in isolation with default A framework can be tested in isolation with default
implementations (standard testing).implementations (standard testing).– A framework should be used to develop an actual A framework should be used to develop an actual
application.application. Rule of thumb: three applications should be Rule of thumb: three applications should be
built before distribution.built before distribution.
Framework EvolutionFramework Evolution
Framework evolution might be categorized as Framework evolution might be categorized as anything beyond use as-is and completion.anything beyond use as-is and completion.
Refactorings can be used to restructure the Refactorings can be used to restructure the framework while preserving its behavior.framework while preserving its behavior.
Design patterns can be applied to make the Design patterns can be applied to make the framework more flexible.framework more flexible.
What happens to applications when frameworks What happens to applications when frameworks evolve?evolve?