Software Design Patterns: Principles and Implementation

Posted by Anonymous and classified in Computers

Written on in English with a size of 4.92 KB

Software Design Patterns and Architecture (CSC3324)


Defining Software Design Patterns

  • A reusable solution to a recurring design problem.

  • It reuses abstract knowledge about problems and solutions.

  • Independent of specific implementations, it acts as a template.

  • It utilizes Object-Oriented Programming (OOP) features such as inheritance and polymorphism.


The Christopher Alexander Definition

“Each pattern describes a problem which occurs over and over again... and then describes the core of the solution... you can use this solution a million times over without doing it the same way twice.”


Architecture vs. Design Patterns

AspectArchitectureDesign Patterns
LevelHigh-levelLower-level (Micro-architecture)
PurposeStructure of the whole applicationSolve subproblems within the application
FocusSystem components and interactionsObject collaborations
ExamplesClient-server, SOAObserver, Singleton, Factory, etc.


Four Essential Elements of a Design Pattern

ElementMeaning
NameUnique identifier
ProblemDescribes when to apply the pattern
SolutionTemplate for solving the problem
ConsequencesResults and trade-offs of applying it

Classification of Design Patterns

ClassificationCategoriesScope
By PurposeCreational, Structural, Behavioral 
By ScopeApplies to classes or objects 

Core Design Pattern Categories

TypePurposeExamples
CreationalObject creation mechanismsSingleton, Factory, Builder, Prototype
StructuralComposing objects into larger structuresAdapter, Bridge, Composite, Façade
BehavioralCommunication between objectsObserver, Strategy, Iterator, Command

The Observer Pattern Explained

ElementDescription
NameObserver
ProblemThe need to reflect state changes in multiple displays
SolutionUse Subject and Observer interfaces; Observers subscribe to changes
ConsequencesLoose coupling between Subject and Observer, but limited optimization


UML Structure of the Observer Pattern

  • Subject: Abstract class. It maintains a list of observers and notifies them of changes.

  • ConcreteSubject: Stores the actual state and sends updates to observers.

  • Observer: An interface for the update() method.

  • ConcreteObserver: Receives updates and refreshes the display accordingly.


Observer Pattern in Practical Applications

This pattern is used when:

  • You need multiple views (e.g., a chart and a table) for the same data.

  • Changes in one place must propagate to all views automatically.

  • The subject should not know the specific details of its observers.


Common Design Patterns and Use Cases

PatternUse Case Example
FaçadeSimplifies or tidies up a set of complex APIs
IteratorProvides a consistent way to loop through a collection
DecoratorDynamically extends object functionality at runtime
CommandEncapsulates requests as objects for flexible undo/redo
StateChanges object behavior based on internal state
StrategyChooses different algorithms at runtime

Related entries: