Using Software Design Patterns Bill Anderson. About me Fox developer since 1987 Fox developer since...
-
Upload
logan-underwood -
Category
Documents
-
view
214 -
download
1
Transcript of Using Software Design Patterns Bill Anderson. About me Fox developer since 1987 Fox developer since...
Using Software Design Using Software Design PatternsPatterns
Bill AndersonBill Anderson
About meAbout me
Fox developer since 1987Fox developer since 1987 Program Director, Los Angeles Visual Program Director, Los Angeles Visual
Foxpro Developers Group (LAFox)Foxpro Developers Group (LAFox) Independent Consultant since 1991Independent Consultant since 1991 SoCal speaker and authorSoCal speaker and author
Design PatternsDesign Patterns
What are patterns? What are patterns? A solution to a problem in a context. A solution to a problem in a context. Similarities to architectural design Similarities to architectural design
issues.issues.
Design Patterns Design Patterns
Four elements to a design patternFour elements to a design pattern NameName When to apply patternWhen to apply pattern Description of elements and Description of elements and
responsibilitiesresponsibilities Consequences of usageConsequences of usage
You’re familiar with patterns!You’re familiar with patterns!
Bridge PatternBridge Pattern
Definition: Decouple an abstraction from Definition: Decouple an abstraction from the implementation so the two can vary the implementation so the two can vary independently.independently.
Fundamental design patternFundamental design pattern Three types of bridgesThree types of bridges
Reference bridgesReference bridges Multiple bridgesMultiple bridges Aggregation bridgesAggregation bridges
Decorator PatternDecorator Pattern
Definition: Attach additional Definition: Attach additional responsibilities to an object responsibilities to an object dynamically.dynamically.
Heuristic: Subclass all “black box” Heuristic: Subclass all “black box” objects (VFP base classes, ActiveX objects (VFP base classes, ActiveX controls, etc.)controls, etc.)
Subclassed a control and changed its Subclassed a control and changed its behavior? Then you know the pattern.behavior? Then you know the pattern.
Adapter PatternAdapter Pattern
Definition: Convert the interface of a Definition: Convert the interface of a class into another interface clients class into another interface clients expect.expect.
Adapters modify interfaces to an Adapters modify interfaces to an object (unlike Decorators, which object (unlike Decorators, which modify behavior of an object). Makes modify behavior of an object). Makes an object look like another.an object look like another.
Template MethodTemplate Method
Definition: Define the skeleton of an Definition: Define the skeleton of an algorithm in an operation.algorithm in an operation.
Used to define a common sequence Used to define a common sequence of eventsof events
Template methods containTemplate methods contain Abstract operation methodsAbstract operation methods Hook operationsHook operations
Iterator PatternIterator Pattern
Definition: Provide a way to access Definition: Provide a way to access elements of an aggregate object. elements of an aggregate object.
Means of traversal handled by Means of traversal handled by iterator object.iterator object.
Should be a container.Should be a container. VFP collection class is ideal.VFP collection class is ideal. Similarities to traversing an array. Similarities to traversing an array.
Aggregate6.Execute()
Iterator.Execute()Aggregate2.Execute()Aggregate3.Execute()Aggregate4.Execute()Aggregate5.Execute()
Aggregate1.Execute()
Observer PatternObserver Pattern
Definition: Define dependency Definition: Define dependency between objects so that if state between objects so that if state change, all dependents are notified.change, all dependents are notified.
Two types of ObserversTwo types of Observers Active (Voyeur)Active (Voyeur) Passive (Publish and Subscribe)Passive (Publish and Subscribe)
Mediator PatternMediator Pattern
Definition: Define an object that Definition: Define an object that encapsulates how a set of objects encapsulates how a set of objects interact. Mediator promotes loose interact. Mediator promotes loose coupling via one communication coupling via one communication point.point.
Used to handle event notification.Used to handle event notification. Mediator is a form of a Passive Mediator is a form of a Passive
Observer.Observer.
Memento PatternMemento Pattern
Definition: Capture an object’s Definition: Capture an object’s internal state so that the object can internal state so that the object can be restored.be restored.
Use this pattern for VFP Use this pattern for VFP housekeeping chores – SET settings, housekeeping chores – SET settings, ON settings, work areas, etc.ON settings, work areas, etc.
Chain of ResponsibilityChain of Responsibility
Definition: Avoid coupling request Definition: Avoid coupling request sender to the receiver by giving sender to the receiver by giving more than one object a chance to more than one object a chance to handle the request. Chain the handle the request. Chain the receiving objects.receiving objects.
Pattern often used in hierarchies – Pattern often used in hierarchies – Error handling, processing import Error handling, processing import data, multi-tier applications, etc.data, multi-tier applications, etc.
Chain of ResponsibilityChain of Responsibility
Business Layer
Data Layer
Presentation Layer
oPresentObj.Delete()
oBizObj.Delete() .StartTransAction()
oCursor.Delete()IF NOT DELETED() DELETEENDIF NOT DELETED()RETURN DELETED()
.EndTransAction()
Abstract Factory PatternAbstract Factory Pattern
Definition: Provide an interface for Definition: Provide an interface for creating families of dependent creating families of dependent objects without specifying their objects without specifying their concrete classes.concrete classes.
Avoid NewObject and CreateObject Avoid NewObject and CreateObject methods – let Factory handle it.methods – let Factory handle it.
VFP data access performance is ideal VFP data access performance is ideal for implementing this pattern.for implementing this pattern.
SummarySummary
Use Software Patterns to keep an Use Software Patterns to keep an application as flexible as possible.application as flexible as possible.
Think in Patterns Think in Patterns You’re already familiar with most patterns.You’re already familiar with most patterns. Use pattern heuristics as a guideline.Use pattern heuristics as a guideline. Understand pattern usage.Understand pattern usage. Don’t get lost in formal definitions.Don’t get lost in formal definitions. Fox Wiki is a great resourceFox Wiki is a great resource
http://fox.wikis.comhttp://fox.wikis.com
Thank you!Thank you!
Remember to fill out your sessionRemember to fill out your session
evaluation. evaluation.
Session slides, white paper, and code Session slides, white paper, and code samples will not be updated.samples will not be updated.