SW Design Principle YoungSu, Son. Microsoft MVP EvaCast Study Leader Devpia Architecture Sysop.

Slides:



Advertisements
Similar presentations
General OO Concepts and Principles CSE301 University of Sunderland Harry R. Erwin, PhD.
Advertisements

GridRPC Sources / Credits: IRISA/IFSIC IRISA/INRIA Thierry Priol et. al papers.
SOLID Object Oriented Design Craig Berntson
5/17/2015 OO Design: Liskov Substitution Principle 1.
Testing and Inheritance What is the relation between the test suite of a superclass and a subclass?
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not.
More Inheritance and LSP CS340100, NTHU Yoshi. More about Inheritance Reuse? – Q1: 你有沒有程式 ” 砍掉重練 ” 的經驗 ? – Q2: 你有沒有 ” 再造輪子 ” 的經驗 ? class Rectangle – Firstly,
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
1 CS4850 Programming Languages Wuwei Shen. 2 Aministrivia Course home page: Reference books: –Programming Languages,
Feb. 23, 2004CS WPI1 CS 509 Design of Software Systems Lecture #5 Monday, Feb. 23, 2004.
Typing Issues and LSP David Rabinowitz. March 3rd, 2004 Object Oriented Design Course 2 Typing Static typing Reliability Catching errors early Readability.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
CSc 335: Three More OO Design Principles
Design Patterns and Principles of Object Oriented Application Development “design patterns are proven techniques used by experienced developers to tackle.
1 OO Design Principles Project Group eXtreme Programming Md. Abul Bashar 07/09/2004.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
1 OO Design Novosoft, 2001 by V. Mukhortov. 2 OO Design Goals  Flexibility Changes must be localized  Maintainability Modules requiring changes can.
Cli/Serv.: rmiCORBA/131 Client/Server Distributed Systems v Objectives –introduce rmi and CORBA , Semester 1, RMI and CORBA.
Ch:10 Component Level Design Unit 4. What is Component? A component is a modular building block for computer software Because components reside within.
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
More Design. Next Tuesday First draft of architectural design –use cases –class diagrams for major classes with responsibilities –sequence diagrams for.
© 2004 Capgemini - All rights reserved SOLID - OO DESIGN PRINCIPLES Andreas Enbohm, Capgemini.
Effective C#, Chapter 1: C# Language Elements Last Updated: Fall 2011.
CSE 301 Exam Revision Lecture
Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution.
Class Design III: Advanced Inheritance Additional References “Object-Oriented Software Development Using Java”, Xiaoping Jia, Addison Wesley, 2002 “Core.
CPSC 372 John D. McGregor Module 4 Session 1 Design Patterns.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Design Principles iwongu at gmail dot com.
Software Design Principles
1 Single Responsibility Principle Open Closed Principle Liskov Substitution Principle Law of Demeter CSC 335: Object-Oriented Programming and Design.
Testing and Inheritance What is the relation between the test suite of a superclass and a subclass?
CS 501: Software Engineering Fall 1999 Lecture 12 System Architecture III Distributed Objects.
OO Design Principles Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, Copyright © INTEKS LLC,
CPSC 871 John D. McGregor Module 5 Session 1 Design Patterns.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Design Patterns: Elements of Reusable Object- Orientated Software Gamma, Helm, Johnson, Vlissides Presented By: David Williams.
Design Patterns Introduction
CORBA (Common Object Request Broker Architechture) Aniket Prabhune Varun Saini Balaprasuna Chennupati Lally Singh.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Evaluating an Object-Oriented Design ©SoftMoore ConsultingSlide 1.
1. Perspectives on Design Principles – Semantic Invariants and Design Entropy Catalin Tudor 2.
SOLID Design Principles
Session 33 More on SOLID Steve Chenoweth Office: Moench Room F220 Phone: (812) Chandan Rupakheti Office: Moench.
Test Code Patterns How to design your test code. 2 Testing and Inheritance Should you retest inherited methods? Can you reuse superclass tests for inherited.
14 Jul 2005CSE403, Summer'05, Lecture 09 Lecture 09: Fundamental Principles and Best Practices for Software Design Valentin Razmov.
Course information Old exam Resit Report Result and walkthrough
Design Patterns: MORE Examples
Design Patterns: Brief Examples
More Design Heuristics
Software Design Principles
Inheritance ITI1121 Nour El Kadri.
MPCS – Advanced java Programming
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
Instructor: Dr. Hany H. Ammar
EECE 310: Software Engineering
Advanced Programming Behnam Hatami Fall 2017.
Software Design Principles
lecture 08, OO Design Principle
08/15/09 Design Patterns James Brucker.
11/29/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
Subtype Polymorphism, Subtyping vs
Software Design Lecture : 14.
619 Final Review Last updated Spring 2010 © : Paul Ammann.
Overview of AIGA platform
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
A (partial) blueprint for dealing with change
Liskov Substitution Principle (LSP)
Presentation transcript:

SW Design Principle YoungSu, Son. Microsoft MVP EvaCast Study Leader Devpia Architecture Sysop

Motivation (How to Make Good SW?) Good World Good Software Policy Law Awareness PrinciplePattern Model Rules

Cells vs Cancer Cell cell cancer cell Cancer cells just have unusual behavior rules

Agenda  Motivation  TSP Solutions Complex Solution Complex Solution Simple Solution Simple Solution  S/W Categories Do you think that Pattern is GPS in SW? Do you think that Pattern is GPS in SW?  Basic Principle used Patterns OCP OCP SRP/ISP SRP/ISP DIP DIP LSP LSP

The Traveling-Salesmen Problem 51!(6.0828*10^62) different trips N location = (N-1)! Possible route = (N-1)! Possible route NP - Complete High Computational Complexity

Complex Solution (Master-Slave Pattern) Master Slaves Parallel Computing Distributed Computing Grid Computing

Simple Solution (Using Perfume) Starting Point Destination As time go on, Perfume fade !! a Path remained the most heavy perfume is the shortest path !! Experts

S/W Categories DomainIndependent20% DomainSpecific65% AppSpecific15% Software Categories pattern pattern pattern pattern pattern pattern pattern pattern pattern pattern Pattern Basic Principle

Basic Principles used Patterns SingleResponsibilityPrinciple OpenClosePrinciple DependencyInversionPrinciple LiskovSubstitutionPrinciple InterfaceSegregationPrinciple

Chapter 1  Open Close Principle S/W Entities (Classes, Modules, Functions, Etc.) Should be Open for Extension, but Closed for Modification. S/W Entities (Classes, Modules, Functions, Etc.) Should be Open for Extension, but Closed for Modification.

OCP  Introduction Mobile Phone Charger Mobile Phone Charger Server/Client System Server/Client System  IDEAS Abstraction is Key! Abstraction is Key! Divide mutable things and immutable things Divide mutable things and immutable things Define Interface between mutable things and immutable things Define Interface between mutable things and immutable things  Known Uses GCC Compiler / Middleware /Command Pattern GCC Compiler / Middleware /Command Pattern  Considerations Shared Module Shared Module Adapter vs Interface Modification Adapter vs Interface Modification Define Abstraction Level Define Abstraction Level

OCP Intro (Mobile Phone Charger) 24 pin 18 pin Mobile Phones When purchase Mobile Phone, Purchase Charger! Re-Buy Use

OCP Intro (Client/Server System) 1 X 1 N X N Server fileRead() Client fileEncode() Server fileRead() byteArrayRead() stringBufRead() Client fileEncode() byteArrayEncode() stringBufEncode()

OCP Intro – cont’d (Client/Server System) InputStream read() byteArray InputStream PipeInputStreamFileInputStream Client encode() 1 X N

IDEAS  Abstraction is Key!!  Divided moral and immoral.  Define Interface between moral and immoral

Abstraction is Key!  Abstraction Don’t equate Abstraction to Ambiguous. Don’t equate Abstraction to Ambiguous. In OO, Abstraction means objects are analyzed In OO, Abstraction means objects are analyzed until they are uniquely identified  Abstraction is Key!! The abstractions are interfaces (abstract classes). The abstractions are interfaces (abstract classes). The unbounded group of possible behaviors is represented by all the possible derivatives classes. The unbounded group of possible behaviors is represented by all the possible derivatives classes. Such a module can be closed for modification Such a module can be closed for modification since it depends upon an abstraction that is fixed. Yet the behavior of that module can be extended Yet the behavior of that module can be extended by creating new derivatives of the abstraction.

Divide mutable things and immutable thins

ImmutableAttributesNameSSNBirthday MutableAttributesWeightFeatureStyle

Define Interface (Bridge/Dike) InputStream read() byteArray InputStream PipeInputStreamFileInputStream Client encode()

Know Use  GCC Compiler  Middleware  Command Pattern

GCC Compiler SourceCodeLexicalAnalyzer Tokenized SyntacticAnalyzer ParsedCode SemanticAnalyzer Optimizer CodeGenerator QualifiedCode ObjectCode FinalCode IntermediateRepresentation SharedModule Close Open

Middleware (Common ORB Architecture) Client in args operation() out args, return DII IDL STUBS ORB INTERFACE IDL SKEL Object Adapter ORB CORE GIOP/IIOP/ESIOPS InterfaceRepositoryIDLCompilerImplementationRepository OBJREF Object(Servant) DSI

Command Pattern

Consideration  Shared Module  Adapter vs Interface Modification  Define Abstraction Level

Shared Module (gcc Compiler) SourceCodeLexicalAnalyzer Tokenized SyntacticAnalyzer ParsedCode SemanticAnalyzer Optimizer CodeGenerator QualifiedCode ObjectCode FinalCode IntermediateRepresentation SharedModule Close Open

Adapter vs Interface Modification When Client demands new requirement!

Adapter vs Interface Modification Most Great Architects have predictability have predictability The Great Architect

Define Abstraction Level

Summary Experience DomainExpert Predictability Persistent

Summary  Related Patterns GOF GOF Template Method PatternTemplate Method Pattern Strategy PatternStrategy Pattern Bride PatternBride Pattern POSA POSA ReactorReactor  GOF Principle “Program to an interface, not to an implementation” “Program to an interface, not to an implementation” “Favor Object Composition over Inheritance” “Favor Object Composition over Inheritance”

Chapter 2  Dependency Inversion Principle Don’t Call Us! We Call You. Don’t Call Us! We Call You.

DIP  Introduction Hollywood Principle Hollywood Principle  IDEAS Inversion Of Control Inversion Of Control Template Method Pattern. Template Method Pattern.  Known Uses Client Server Programming Client Server Programming CORBA Event Service CORBA Event Service  Summary

DIP Intro (Hollywood Principle) Applicants Manager Don’t Call us!!

DIP Intro (Hollywood Principle) Applicants Manager Don’t Call us! We Call You!!!

IDEAS  Inversion Of Control  Template Method Pattern

Inversion of Control

Template Method Pattern doQuery(dbName, Query) { string dbCommand; dbCommand = FormatConnect(dbName); dbCommand = FormantSelect(Query); ///….return DataSet } Query Template +doQuery() #FormatConnect() #FormatSelect() OracleQT #FormatConnect() #FormatSelect() SqlSvrQT #FormatConnect() #FormatSelect()

Know Use  Client Server Programming Blocking Model Blocking Model Polling Model Polling Model Publisher-Subscriber Model Publisher-Subscriber Model  CORBA Event Service  Timer Service

requestA() Server Client A_Handler B_Handler requestB() requestA() Client/Server System (Blocking Model - Sync) Client waits When Server arrive Response

requestA() Server Client A_Handler B_Handler requestB() Client/Server System (Polling Model - Async) Check()

Client/Server System (Publisher-Subscriber Model) Publisher(Server) Event Channel (Yellow Book) Subscribers

CORBA Event Service (Publisher-Subscriber Model) Event * Subscriber consume createsreceives Event Channel attachPublisher detachPublisher attachSubscriber detachSubscriber pushEvent Filter filterEvent Publisher produce Structure attachSubscriber produce pushEvent pushEventconsumedetachSubscriber : Event : Subscriber : Event Channel : Publisher event

Summary  Related Patterns GOF GOF Command PatternCommand Pattern Observer PatternObserver Pattern POSA POSA Publisher/Subscriber PatternPublisher/Subscriber Pattern Event ChannelEvent Channel  DIP simplifies complex communications between objects apply a not-stop talker object apply a not-stop talker object

Chapter 3  Liskov Substitution Principle In any time, In any time, sub-type could substitute base-type.

LSP  Introduction Starbucks Coffee Starbucks Coffee  IDEA Function Function Class Class  Known Uses ODBC/JDBC ODBC/JDBC  Considerations Inheritance vs Delegation Inheritance vs Delegation Is-A Relationship != Inheritance Is-A Relationship != Inheritance  Summary

LSP Intro (Starbucks Coffee) A Honest Good A Counterfeit Customer

IDEA  Function Function that use pointers or references to base classes must be able to use objects of derived classes without knowing it. Function that use pointers or references to base classes must be able to use objects of derived classes without knowing it.  Class as argument If a method has an object of a class as an argument, the same method should be able to work with an object of derived class. If a method has an object of a class as an argument, the same method should be able to work with an object of derived class.

Know Use  ODBC/JDBC

ODBC/JDBC ODBC(JDBC) API Application ODBC (JDBC) Driver Manager MSSQL Driver Oracle Driver

ODBC/JDBC (Template Method Pattern) doQuery(dbName, Query) { string dbCommand; string dbCommand; dbCommand = FormatConnect(dbName); dbCommand = FormatConnect(dbName); dbCommand = FormantSelect(Query); dbCommand = FormantSelect(Query); ///….return DataSet ///….return DataSet} Query Template +doQuery() #FormatConnect() #FormatSelect() OracleQT #FormatConnect() #FormatSelect() SqlSvrQT #FormatConnect() #FormatSelect()

Consideration  Collection Framework in Java Inheritance vs Composition Inheritance vs Composition  Is-A Relationship != Inheritance

Collection Framework in Java Set Collection List SortedSet

Collection Framework in Java (Cont’d - Sample Code) … main() { String[] infoValues = new String[]{“info1”,“info2”,“info3”}; List infoList = Arrays.asList(infoValues); infoList = infoHelper.addInfo(infoList); } … class Infohelper { public static java.util.List addInfo(Java.util.List currentInfo) { String info = “new info”; curretList.add(info); return currentinfo } Excpetion in thread “main” java.lang.UnsuppertedOperationException at java.util.AbstractList.add(AbstractList.java:150) LSPViolation

Collection Framework (Inheritance vs Composition) Set Collection List SortedSet SetList SortedSet Collection SetList SortedSet modified unmodified

Class Rectangle { public : public : void SetWidth(double w) { Width = w; } void SetHeight(double h) { Height = h; } double GetHeight() {return Height; } double GetWidth() { return Width; } double GetArea() {return width*height;} private : private : double Width; double Height; } Is-A Relationship (Rectangle & Square)

class Sequre extends Rectangle { public : void SetWidth(double w) { super.SetWidth(w); super.SetHeight(w); } void SetHeight (double h) { super.SetWidth(h); super.SetHeight(h); } public void calc (Rectangle r) { r.setWidth(10); r.setHeight(2); assert(r.getArea() == 20); } LSPViolation

The Tao of LSP (Contract)  In order for the LSP to hold, and with it the OCP, and with it the OCP, all derivatives must conform to the behavior that clients expect of the base classes that clients expect of the base classes that they use. that they use.

Design by Contract (DBC)  Using the scheme methods of classes declare preconditions and postconditions.  The preconditions must be true in order for the method to excute.  Upon completion, the method guarantees that the postcondition will be true. Recaangle :: SetWidth(double w) { … Assert((itsWidth == w) && (itsHeight == old.itsHeight)); Assert((itsWidth == w) && (itsHeight == old.itsHeight));}

Summary  Related Patterns GOF GOF Chain-Of-Responsibility PatternChain-Of-Responsibility Pattern  LSP Considers Design by Contract (IOPE) Considers Design by Contract (IOPE)

References  “OO S/W Design Principle”, choi sang-hun et al, 2005  Design Patterns: Elements of Reusable Object-Oriented Software, E. Gamma, R.Helm, R. Johnson, J. Vlissides, Addison-Wesley, 1995  The Open-Closed Principle, Bertrand Meyer, 1998  CORBA, Steve Vinoski, IEEE Communications Magazine, February,  Schmidt Home Page