Dan Fleck CS 421 George Mason University

Slides:



Advertisements
Similar presentations
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Advertisements

DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Design Patterns CS is not simply about programming
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Developed by Reneta Barneva, SUNY Fredonia Component Level Design.
Design Patterns Ref : Chapter 15 Bennett et al. useful groups of collaborating classes that provide a solution to commonly occuring problems. provide.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Design Patterns.
Design Dan Fleck CS 421 George Mason University. What is the design phase? Analysis phase describes what the system should do Analysis has provided a.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
CSSE 374: Introduction to Gang of Four Design Patterns
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
12 Systems Analysis and Design in a Changing World, Fifth Edition.
1 SAD2 - UML 4 th Lecture Class Diagram in Construction Phase Patterns Case Study Lecturer: Dr Dimitrios Makris
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
Design Design and Software Architecture. The design phase The analysis phase describes what the system should be doing The design phase describes how.
Coming up: What is the design phase? Design (Ch 8 and Ch 12) Dan Fleck CS 421 George Mason University.
Chapter 17 GRASP: Designing Objects with Responsibilities. 1CS6359 Fall 2011 John Cole.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
GRASP: Designing Objects with Responsibilities
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
Structural Design Patterns
ECE450S – Software Engineering II
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
Design Patterns Yonglei Tao. Design Patterns  A design pattern describes a recurring design problem, a solution, and the context in which that solution.
A Few Review Questions Dan Fleck Fall System Test Case Enter invalid username in the input box Able to enter text Enter invalid password in the.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Coming up: What is the design phase? Design Dan Fleck CS 421 George Mason University.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Design Patterns Introduction
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Patterns in programming
Copyright © Jim Fawcett Spring 2017
GRASP – Designing Objects with Responsibilities
Object-Oriented Programming Concepts
Design Patterns Spring 2017.
The Movement To Objects
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Week 2, Day 1: The Factory Method Pattern
Introduction to Design Patterns
Behavioral Design Patterns
object oriented Principles of software design
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
How to be a Good Developer
Advanced Programming Behnam Hatami Fall 2017.
Component-Level Design
Introduction to Design Patterns Part 1
08/15/09 Design Patterns James Brucker.
Object Oriented Design Patterns - Creational Patterns
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
CS 350 – Software Design Singleton – Chapter 21
Applying Use Cases (Chapters 25,26)
Applying Use Cases (Chapters 25,26)
Object Oriented System Design Responsibilities
Presentation transcript:

Dan Fleck CS 421 George Mason University Design Dan Fleck CS 421 George Mason University Coming up: What is the design phase?

What is the design phase? Analysis phase describes what the system should do Analysis has provided a collection of classes and descriptions of the scenarios that the objects will be involved in. These functions are clustered in groups with related behavior. The design phase is to work out how the system should do these things. This is the goal of the design phase. Coming up: Analysis --> Design

Analysis --> Design Coming up: Analysis --> Design

Analysis --> Design Coming up: Analysis --> Design

Analysis --> Design Coming up: Analysis --> Design

Analysis --> Design Coming up: Oversimplification

Oversimplification Analysis Design Classes Objects Attributes Operations Relationships Behavior Design Objects Data Structures Algorithms Messaging Control Coming up: The Design Spec

The Design Spec Architecture Design - Component design - UI design Layers of the software (e.g.model, view, controller (MVC)) Categories of classes (e.g. UI, Business logic, interfaces) Component design - Description of classes/methods/algorithms State machines for classes UI design sample screens UI guidelines/standards we’re using detailed description of how UI components work Data design - database design data structures we’re using. Coming up: The Design Spec

The Design Spec But really, how do I do it? Find examples and use what you think is helpful from them! http://www.mhhe.com/engcs/compsci/pressman/graphics/Pressman5sepa/common/cs2/design.pdf http://www.cmcrossroads.com/bradapp/docs/sdd.html Coming up: The Design Spec

The goal of design is to think with your brain, not your hands The goal of design is to think with your brain, not your hands! - Dan Fleck Coming up: Applied Design

Applied Design We know what to do now, but that is just a set of documents.. How do we create a GOOD design? Coming up: Good Design

Good Design Design Principles Design Patterns Design Metrics What should you try to do? Design Patterns How have people done it before you? Design Metrics How do you know you have done it well? Coming up: Single Responsibility Principle

Single Responsibility Principle Each class should have a single overriding responsibility (high cohesion) Each class has only one reason for why it should change Coming up: Example: Paperboy and the Wallet

Example: Paperboy and the Wallet Customer getFirstName() getLastName() getWallet() PaperBoy’s getPayment method: payment = 2.00; // “I want my two dollars!” Wallet theWallet = myCustomer.getWallet(); if (theWallet.getTotalMoney() > payment) { theWallet.subtractMoney(payment); } else { // come back later and get my money } Wallet addMoney(int a) subtractMoney(int a) countMoney() What is wrong with this? Coming up: Principle of Least Knowledge (aka Law of Demeter)

Principle of Least Knowledge (aka Law of Demeter) “Only talk to your immediate friends” Object O has a method M. M may call other methods in O M may call methods of any parameter passed into the M method M may call methods of any object it creates M can call methods on any object contained in O Purpose: Reduce Coupling Coming up: Principle of Least Knowledge (aka Law of Demeter)

Principle of Least Knowledge (aka Law of Demeter) Simplified: I can play by myself I can play with toys given to me I can play toys I made myself I can play with my own toys (but not take them apart) Purpose: Reduce Coupling Coming up: Example: Paperboy and the Wallet

Example: Paperboy and the Wallet Customer getFirstName() getLastName() getWallet() Bad because the paperboy needs to know about the Wallet, and also the customer has to hand the wallet to the paperboy Wallet doesn’t model the real world and lets paperboy have WAY to much access! addMoney(int a) subtractMoney(int a) countMoney() What is wrong with this? Coming up: Example: Paperboy and the Wallet

Example: Paperboy and the Wallet Customer getFirstName() getLastName() getPayment(int amt) PaperBoy’s getPayment method: payment = 2.00; // “I want my two dollars!” int amt= myCustomer.getPayment(payment); if (amt >= payment) { // say thanks! } else { // come back later and get my money } Wallet addMoney(int a) subtractMoney(int a) countMoney() Better – paperboy only accesses what he needs and models the real world! This example from: http://www.ccs.neu.edu/research/demeter/demeter-method/LawOfDemeter/paper-boy/demeter.pdf Coming up: Dependency Inversion Principle

Dependency Inversion Principle Depend on abstractions, not concretions Program to interfaces not implementations Program to most abstract class possible Why? Concrete classes may change a lot. Abstract classes/Interfaces generally change very little. How can we ensure interfaces change very little? See next slide! Answer: Add interfaces instead of modifying them. Coming up: Interface Segregation Principle

Interface Segregation Principle Don’t make large multipurpose interfaces – instead use several small focused ones. Don’t make clients depend on interfaces they don’t use. Class should depend on each other through the smallest possible interface. Why? When I change something I want to minimize changes for everyone else. Coming up: Remove Cyclic Dependencies

Remove Cyclic Dependencies Do not have cyclic dependencies in your packages Decomposition into independent modules Why? GUI - Makes testing a much bigger problem Logic BusinessLogic UserLogic ErrorHandling Coming up: Design Patterns

Design Patterns Proven solutions to common problems Capture design expertise Aid in meeting quality metrics Core patterns are from the “Gang of Four (GoF)” OOPSLA - 1994 Coming up: Singleton Pattern

Singleton Pattern Problem: I want to limit the application to only one instance of a particular class, but need global access to that class. Normally used to control access to key resources. Solution? override new, make static accessor method. Coming up: Singleton Pattern (in Java)

Singleton Pattern (in Java) public class MySingleton { private static MySingleton instance; private MySingleton() { // do anything you need to do } public static MySingleton getInstance() { if (instance == null) instance = new MySingleton(); return instance; Coming up: Factory (GoF95)

Factory (GoF95) Define an interface for a group of objects Create a Factory to decide which specific object needs to be instantiated Think of a multi-document application framework. An application object may know when an object needs to be created, but not which object. How do we create the correct object when needed? Can also be used when a complex initialization of objects is necessary, for instance when aggregation is heavily used. Can also be used to take advantage of memory-optimization like object pools, cached objects, etc. Coming up: Factory (GoF95)

Factory (GoF95) Socket EncryptedSocket Encryption instance:IEncryptFactory cipher: Encryption encryptOut decryptIn Encrypts/Decrypts with EncryptionFactory DESEncryption RSAEncryption Requests Creation Creates CreateEncryption(Key): Encryption <<interface>> IEncryptFactory CreateEncryption(Key): Encryption Coming up: Command (GoF95)

Command (GoF95) Encapsulate commands in objects, so we can queue them, undo them or make macros. Abstract Command + manager:CmdMgr * MacroCommand Concrete Command +doIt():bool +undoIt():bool - data +doIt():bool +undoIt():bool +doIt():bool +undoIt():bool Coming up: Flyweight (GoF95)

Flyweight (GoF95) I have a bunch of classes, but I need to minimize the number of objects I am using. Instances of the objects contain the same information and can be used interchangeably Avoid the expense of multiple instances. Example: DocChar class used to hold characters in a line of text Coming up: Visitor (GoF95)

Visitor (GoF95) If you need to perform an operation in multiple objects in a complex structure you could create the logic in each class. OR…the visitor pattern creates a single class that implements the logic and knows how to “visit” each object in your complex structure Coming up: Visitor (GoF95)

Visitor (GoF95) I need to apply different operations to a collection of objects. I want to centralize these operations I want to reduce coupling For example in a word processor, grammar check, spell check, table of contents builder, outliner all need to traverse the document. Coming up: Visitor Diagram

Visitor Diagram Object with Structure concrete concrete visitor navigates Individual Elements Visitor Coming up: Design Patterns Summary

Design Patterns Summary Many design patterns exist Implementations are usually available in every language Use them as guides where appropriate and make sure you understand the tradeoffs for each one. They aren’t always good for YOUR situation Coming up: Design Metrics

Design Metrics Class Size Methods per class Lack of Cohesion (count of methods with dissimilar purpose) Coupling Between Classes (count of other classes that this class refers to) Depth of Inheritance Tree Method Complexity - tools can do this Coming up: Design Summary

Design Summary The design phase is when you plan HOW you implement your analysis Use Design Principles Design Patterns Design Metrics Coming up: What should you know

What should you know Analysis = what the system should do Design = how it should do it Meaning of the parts of the design spec Design Principles: Single Responsibility Principle - write it Law of Demeter. Describe it and state why it is good. 3 rules of Dependency Inversion Principle Why you need to remove cyclic dependencies Metrics Definition of cohesion and coupling - not how to calculate it, but what it means! Be able to describe patterns - singleton, factory, command Coming up: References

References Luc Berthouze, University of Sussex, http://www.informatics.sussex.ac.uk/users/lb203/se/SE08.pdf Robert Martin, Principles and Patterns, http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf Bob Waters, Georgia Tech, CS2340 Slides, http://www.cc.gatech.edu/classes/AY2007/cs2340_summer/ End of presentation