0% found this document useful (0 votes)
5 views26 pages

COM423 9-Additional Design Principles

The document discusses additional design principles in object-oriented analysis and design, focusing on cohesion, coupling, and separation of responsibilities to enhance system construction and maintainability. It introduces design patterns such as Singleton, Adapter, and Observer, which serve as templates for solving common problems in software design. The principles of protection from variations and indirection are emphasized to stabilize systems and reduce coupling between components.

Uploaded by

bed-com-43-21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views26 pages

COM423 9-Additional Design Principles

The document discusses additional design principles in object-oriented analysis and design, focusing on cohesion, coupling, and separation of responsibilities to enhance system construction and maintainability. It introduces design patterns such as Singleton, Adapter, and Observer, which serve as templates for solving common problems in software design. The principles of protection from variations and indirection are emphasized to stabilize systems and reduce coupling between components.

Uploaded by

bed-com-43-21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

COM 423 – Object-Oriented Analysis

and Design
Additional Design principles
20 March 2018
Overview
 We continue to elaborate on the fundamental principles
cohesion, coupling and separation of responsibilities
 In order to
 Establish best practices in system construction
 Design patterns, or templates
 Design for enterprise-level and Web-based systems
 Distributed and networked environments

 And also introduce new ones to


 Enhance flexibility and maintainability
 Protect and stabilize systems
 Protection from variations and indirection
2 Kondwani G. Munthali (PhD), 3/20/2018
Department of Computer Science
Design Principles and Patterns
 With object responsibility discussed earlier; an object is
responsible for
 Maintaining its own attributes (even getting info from other objects
of need be)
 Creating all objects it depends on
 Better yet, have a general responsibility for it to be an expert on
certain sets of information
 By having the information itself or having navigation visibility and access to
other objects that do have the information
 As such object responsibility helps to design logical and easily
maintained systems
 When used along side cohesion and coupling

3 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Protection From Variations
 A principle that states that parts of a system that are
unlikely to change should be segregated (protected) from
those that will need to be changed
 Drives the multilayer design pattern
 Stable business logic can be protected from variations in the
user interface
 Changes in the business logic are isolated to the controller
class

4 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Indirection
 Indirection is an implementation of the protection from
variations principle
 Decouples classes or other system components by
placing an intermediate class(es) between them to serve
as a link
 Used in many corporate security systems between an
internal network and the Internet
 Eg firewalls and proxy servers

5 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
What is a pattern?
 Pattern and templates are used in all disciplines and in
everyday life
 Recipe used by a chef; tailor uses a pattern to cut fabric for a
suit; engineers for buildings
 Are created to solve problems
 These become a solution that is general enough to be used
over and over again
 Over time they become standards

6 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Importance of Design Patterns
 Standard design templates can speed OO design
 Patterns can exist at different levels of abstraction
 At the most concrete level, as a class definition with code
 Eg Use case controller
 At the most abstract level, as an approach to a problem
 Eg Three-layer design

7 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Importance of Design Patterns
 Patterns should
contain five main
elements
 Pattern name,
problem,
solution,
example,
benefits and
consequences
 Pattern
description for
the controller
pattern
8 Kondwani G. Munthali (PhD), 3/20/2018
Department of Computer Science
Basic Design Patterns
 The authors of Elements of Reusable Object-Oriented Software
(referred to as the Gang of Four) developed a basic classification
scheme for 23 patterns
 Scores of other patterns have been defined
 For example, both Java and .NET have sets of enterprise patterns

9 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Design patterns
 We will look at one of each type in our discussion
 Singleton
 Adapter
 Observer
 Read more about the other patterns in your own time

10 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Singleton Pattern
 For classes that must have only one instance, but need to
be invoked from several classes and locations within the
system
 A database connection class
 The class itself controls the creation of only one instance
 Has a static variable of the class that refers to the object that is
created
 A class method is defined that is used to get the reference to
the object eg getInstance()
 The first time getInstance() is called, it instantiates the object and
returns a reference to it
 On later calls to the method it simply returns a reference to
the already instantiated object

11 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Singleton Pattern
 Singleton
pattern
template
 Simple and
elegant

12 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Singleton Pattern
 All constructors are declared as private, why?
 As it is code, as a designer you need to stereotype it as
<<singleton>>

13 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Adapter Pattern
 Plugs an external class into a system – just like an
electrical adapter
 Converts the method calls from within the system to match
the method names in the external class
 A standard solution for protection from variations
 Insulates the system from frequently changing classes
 An interface is frequently used to specify and enforce the
use of correct method names

14 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Adapter Pattern….
 Adapter
pattern
template

15 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Adapter Pattern….
 Adapter pattern template
 Standard method for protection from variation
 TaxCalculatorIf class is an interface for the system inherited by
TaxCalcAdapter
 TaxCalcAdapter then provides the method logic ny extending a
call to the ‘adapted’ class ABCTaxCalculator methods
findTax1/2

16 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Observer pattern
 Used to handle event-processing and reduce coupling
 The domain class
 Allows other classes to “subscribe” as listeners eg the view
layer
 But good design demands that the two be not coupled
 Ie window can send messages to domain but not viceversa
 The idea is to be able to link classes without permanently
coupling them
 Ie dynamic and temporary coupling
 Ie when you have an object that needs to share it's state
with others, without knowing who those objects are
17 Kondwani G. Munthali (PhD), 3/20/2018
Department of Computer Science
Observer pattern…
 Three classes in the Create new order use case
 Order and Customer windows have navigation visibility to Order
 On the customer window, ‘Past purchase’ and ‘Year-to-end’ need to be updated as the
order gets filled
 But the info to update with is in Order class which has no visibility of the Customer window

18 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Observer pattern…
 Why not just put a reference to Customer window in
the Order object then?
 Violates coupling principle, how?

19 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Observer pattern…
 A better solution is to have Customer window “listen”
for any changes to the Order object
 When it “hears” of a change in an order, it updates the
appropriate fields

20 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Observer pattern…
 The Order class must then contain mechanisms that
 Allow other classes to “subscribe” as listeners, and
 “publish” the changes to the listeners when they occur

21 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Observer pattern…implementation
 Changes to Order class are in bold that include
 An array of object references listing all subscribers listening
 A method called by potential listeners wishing to subscribe
 A method called ‘notify’
 An interface class along side the order class

22 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Observer pattern…implementation
 An interface class (publisher) along side the order class
 CustomerWindow has navigation visibility to Order and also
inherits from OrderListener interface to know method to
implement
 OrdeListener is dependent on the Order class

23 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Observer pattern…implementation
 When a class (CustomerWindow) wants to listen it calls
the addOrderListener sending a reference to itself as a
parameter
 Notify() iterates through the object array and sends a
message to each object referenced in the array

24 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Observer pattern…implementation
 Since the link from Order to CustomerWindow is
dynamic and temporary, it has no side effects on the code
 As opposed to a fully coupled relationship
 Here again multiple windows can listen on the order
amount changing without changes to the Order class

25 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science
Observer pattern…
 Observer
pattern
template

26 Kondwani G. Munthali (PhD), 3/20/2018


Department of Computer Science

You might also like