sea side software engineering annotations annotation 2: design patterns one hour presentation to...
TRANSCRIPT
![Page 1: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/1.jpg)
SEA Side Software Engineering Annotations
• Annotation 2: Design Patterns
• One hour presentation to inform you of new techniques and practices in software
development.
• Professor Sara Stoecklin• Director of Software Engineering- Panama City
• Florida State University – Computer Science
• 850-522-2091
• 850-522-2023 Ex 182
![Page 2: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/2.jpg)
Design Patterns
Definition:
Pattern: A representation of a proven solution.
Problem
Applicable Forces
Solution
ConsequencesBenefits
![Page 3: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/3.jpg)
Design Patterns
Definition:
Anti-Pattern: A solution pair not a problem solution pair
Anti Pattern Solution
Contextual Causes
Refactored Solution
ConsequencesBenefits
Symptoms and Consequences
![Page 4: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/4.jpg)
Design Patterns
Fundamental Design Patterns
Creational Design Patterns
Partitioning Patterns
Behavioral Patterns
Concurrency Patterns
![Page 5: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/5.jpg)
Delegation **
Interface
Marker Interface
Immutable
Proxy
Fundamental Design Patterns (FDP)
![Page 6: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/6.jpg)
FDP - Delegation
Synopsis:
Delegation is a fundamental method to extend and reuse a classes functionality ( behavior or methods)
Context:
Allows instances of a class to play multiple roles.
Solution:
Reuse and extend behavior using delegation
![Page 7: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/7.jpg)
FDP - Delegation
class x
public void methodforx () { }
class y
x _x = new x();
……
_x.methodforx ( ) DELEGATION
![Page 8: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/8.jpg)
FDP - Delegation - Example
Delegator Delegateeuses 1
1
InstanceClass or Instance
![Page 9: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/9.jpg)
FDP - Delegation - Example
FlightSegment LuggageCompartment1.1 checkluggage() 1
1
1. checkluggage()
Instance
![Page 10: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/10.jpg)
FDP - Delegation - Example
// Instance of this class represent a flight segment.
class FlightSegment {
LuggageCompartment luggage;
/**
* Check a piece of luggage
* @param piece The piece of luggage to be checked.
* @exception LuggageException if piece cannot be checked.
*/
void checkLuggage(Luggage piece) throws LuggageException {
luggage.checkLuggage(piece);
} // checkLuggage(Luggage)
} // class FlightSegment
DELEGATION
![Page 11: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/11.jpg)
Delegation **
Interface - Allows classes with some similar data to use polymorphism to execute behavior.
Marker Interface - used for utilities – allows investigation into class information without knowing they are an instance of a particular class.
Immutable – forbids any of an object’s state information to change after the object is created.
Proxy - forces method calls to an object indirectly.
Fundamental Design Patterns (FDP)
![Page 12: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/12.jpg)
Creational Design Patterns
Factory Method **
Abstract Factory
Builder
Prototype
Singleton
Object Pool **
![Page 13: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/13.jpg)
CDP - Factory Method
Synopsis:
Need for a class to reuse with arbitrary data types. Reusable class remains independent of the classes it instantiates by delegating the choice of which class to instantiate to another object and referring to the newly created object through a common interface.
Context:
Creates a framework to support instantiations of various data types.
![Page 14: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/14.jpg)
CDP - Factory Method
Solution:
Proxy object and the service providing object must either be instances of a common super class or implement a common interface.
![Page 15: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/15.jpg)
CDP - Factory Method - Example
You have an application such as MS Office.
You want to perform some common functions with all the files.
Example of common functions might be open file, save file, etc.
The only difference is that the functions are done on different file types such as word doc files, excel xls files and PowerPoint ppt files.
You could write several independent functions for each of the different types but the code would be very similar with only the data type as a difference.
Factory method allows you to build a framework for common functions with only a few classes that reuse methods for each type.
![Page 16: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/16.jpg)
Manage Files
file commands
ManageDoc Files
doc file commands
ManageXls Files
xls file commands
ManagePpt Files
ppt file commands
Make one Function
CDP - Factory Method - Example
![Page 17: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/17.jpg)
CDP - Factory Method - Example
Document Applicationedits 1
*
MyDocument May be doc, xls, or ppt.
![Page 18: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/18.jpg)
Write to Socket
stream
CDP - Factory Method - Example
Socket
But you also wish to have strings in which you encrypt the data.And you write an encrypted DataStream and read back an encrypted Data Stream decrypt it.
string
Suppose you have a process which reads and writes a DataStream to a socket.
Read from Socket
stream Socketstring
![Page 19: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/19.jpg)
Write to Encrypted
Socket
encrypted stream
CDP - Factory Method - Example
EncryptedSocketencrypted string
Encrypt Data
stringWrite to
EncryptedSocket
encrypted stream
EncryptedSocketencrypted string
Read from Socket
encryptedstream
Socketencrypted stringDecrypt
Data
decrypted string
But now you realize that there are several different encryption algorithms and codes you wish to use.
![Page 20: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/20.jpg)
CDP - Factory Method - Example
Encrypt Data
string Write to Encrypted
Socket
encrypted stream
EncryptedSocketencrypted String #1
algorithm # 1
The process to encrypt differs in using many different different algorithms (function/method) and type of string output must be written for each type.
Encrypt Data
string Write to Encrypted
Socket
encrypted stream
EncryptedSocketencrypted String #2
algorithm # 2
Encrypt Data
string Write to Encrypted
Socket
encrypted stream
EncryptedSocketencrypted String #n
algorithm # n
![Page 21: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/21.jpg)
CDP - Factory Method - Example
Encrypt Data
string Write to Encrypted
Socket
encrypted stream
EncryptedSocketencrypted String
algorithm # 1
algorithm # 2
algorithm # n
The factory pattern allows you to have a framework that will handle any type of algorithm and encrypted data.
concrete product
![Page 22: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/22.jpg)
CDP - Factory Method - Example
Encryption
Socket
encrypt, decrypt 1
*
DESEncryption
EncryptedSocket
Transcription
EncryptionFactory
EncryptionFactoryIF
creates
requestCreation
creates1
1
*
*
*
1
Concrete Product
Product
Factory
Socket
EncryptedSocket
Interface
Creation Requester
1
2
3
4
5
6
![Page 23: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/23.jpg)
CDP - Object PoolSynopsis:
Manages reuse of objects when a type of object is expensive to create or only limited number needed.
Context:
You wish to limit access to a resource.
Solution:
Create a reusable class to collaborate with other objects for a limited amount of time.
Create a reusable pool to manage reusable objects for use by client objects.
![Page 24: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/24.jpg)
Allow DatabaseAccess
database access
Suppose you have a database systems that need to allow only a limited number of accesses to the database at one time.
CDP - Object Pool
database access requested
You must write a counting semaphore to protect this resource from having more than the limited access.
![Page 25: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/25.jpg)
CDP - Object Pool
Clientmanage objects
ReusablePool
uses
Reusable
Reusable Pool
![Page 26: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/26.jpg)
Partitioning Patterns
Layered Initialization **
Filter
Composite
![Page 27: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/27.jpg)
PP - Layered Initialization
Synopsis:
You need multiple implementations with common logic in super and specialized in subs.
However the common logic decides which specialized subclass to create.
Therefore layered initialization encapsulates common and specialized logic to create the multiple implementations.
![Page 28: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/28.jpg)
PP - Layered Initialization
Context:
You have a piece of logic that requires partial execution prior to determining which subclass methods might be used.
You need to layer the initializations of the objects to process the complex logic or complex data.
![Page 29: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/29.jpg)
PP - Layered Initialization
Forces:
A specialized class must be chosen to process complex data.
Constructor of the specialized classes and their sub classes are invoked after it has been decided which specialized class to instanciate.
Solution:
Essence of this pattern is to layer the initializations of the objects participating in the pattern.
![Page 30: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/30.jpg)
PP - Layered Initialization
1. Objects that performs logic common to all cases is initialized
2. Initialization concludes by determining the class to instantiate
3. Specialized class constructor performs next layer of initialization logic.
4. After all initialization, one top-level object exist for logic
5. If method needs more specialized logic, it calls method one layer down
Consequences:
Complexity of initialization of objects using data requires analysis before initialization can proceed.
![Page 31: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/31.jpg)
ResolveBusiness
Rules
query request
PP - Layered Initialization
trigger to resolve business rule
Suppose you have a business rule engine which must select a typeof database on which to query to resolve issues in the rule base.
SelectDatabase
Perform OracleQuery
Perform DB2
Query
Perform n
Query
Oraclequery
DB2query
nquery
You cannot perform query until you know what type of database
![Page 32: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/32.jpg)
ResolveBusiness
Rules
query request
PP - Layered Initialization
trigger to resolve business rule
You need to initialize the database prior to query.
SelectDatabase
Perform OracleQuery
Perform DB2
Query
Perform n
Query
Oraclequery
DB2query
nquery
InitializeDatabase
![Page 33: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/33.jpg)
PP - Layered Initialization
DataQueryFactoryIF DataQueryrequest creation
DataQueryImplFactory
OracleQuery DB2Query …..
DataQueryImplIF
creates
uses
Data Query factory method object appears like this.
ServiceImpFactoryIF
ServiceImpFactory
Service
ServiceImpIIF
![Page 34: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/34.jpg)
Behavioral Patterns
Chain of Responsibility State
Command Null Object
Little Language Strategy **
Mediator Template Method
Snapshot Visitor
Observer **
![Page 35: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/35.jpg)
Write to Socket
stream Socket
But you also wish to have strings in which you encrypt the data.And you write an encrypted DataStream and read back an encrypted Data Stream decrypt it.
string
REDO Suppose you have a process which reads and writes a DataStream to a socket.
Read from Socket
stream Socketstring
BP - Observer
![Page 36: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/36.jpg)
Document Applicationedits 1
*
MyDocument May be doc, xls, or ppt.
BP - Observer
![Page 37: SEA Side Software Engineering Annotations Annotation 2: Design Patterns One hour presentation to inform you of new techniques and practices in software](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bf781a28abf838c81bbd/html5/thumbnails/37.jpg)
Concurrency Patterns
Single Threaded Execution
Guarded Suspension
Balking
Scheduler
Read/Write Lock
Producer-Consumer
Two-Phase Termination