CHAPTER 5: PRINCIPLES OF DETAILED DESIGN

Similar documents
CHAPTER 5: PRINCIPLES OF DETAILED DESIGN. Software Engineering Design: Theory and Practice

CHAPTER 6: CREATIONAL DESIGN PATTERNS

Testing Object-Oriented Applications. Slide Set to accompany. Software Engineering: A Practitioner s Approach, 7/e by Roger S.

Object-Oriented Design

Ingegneria del Software Corso di Laurea in Informatica per il Management. Software quality and Object Oriented Principles

CHAPTER 6: CREATIONAL DESIGN PATTERNS

Testing Object-Oriented Applications. Slides copyright 1996, 2001, 2005, 2009 by Roger S. Pressman. For non-profit educational use only

Component-Level Design. Slides copyright 1996, 2001, 2005, 2009 by Roger S. Pressman. For non-profit educational use only

Object-Oriented Design

CHAPTER 4: PATTERNS AND STYLES IN SOFTWARE ARCHITECTURE

Summary of the course lectures

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

!"#$%&'()*+,-*,--)./00#'1)2)345"645"%()

Design Concepts. Slide Set to accompany. Software Engineering: A Practitioner s Approach, 7/e by Roger S. Pressman

Software Engineering CSC40232: SOFTWARE ENGINEERING. Guest Lecturer: Jin Guo SOLID Principles sarec.nd.edu/courses/se2017

17.11 Bean Rules persistent

Agile Software Development

CS485/540 Software Engineering Architecture and Component Design (Chs. 9,10)

Software Engineering

Software Testing Strategies. Slides copyright 1996, 2001, 2005, 2009, 2014 by Roger S. Pressman. For non-profit educational use only

The Nature of Software. Slides copyright 1996, 2001, 2005, 2009, 2014 by Roger S. Pressman. For non-profit educational use only

User Interface Design. Slide Set to accompany. Software Engineering: A Practitioner s Approach, 7/e by Roger S. Pressman

CSC207H: Software Design SOLID. CSC207 Winter 2018

OO Class Design Principles

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

Today's Agenda. References. Open Closed Principle. CS 247: Software Engineering Principles. Object-Oriented Design Principles

Component-Level Design

Open Closed Principle (OCP)

08. DESIGN PRINCIPLES. Originality is Overrated PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT

Single Responsibility Principle (SRP)

Slides copyright 1996, 2001, 2005, 2009, 2014 by Roger S. Pressman. For non-profit educational use only

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt

Conception Orientée Objets. Programmation SOLID

Abstraction. Design fundamentals in OO Systems. Fundamental Software Development Principles

Outline. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Benefits of Subtype Polymorphism. Subtype Polymorphism

Why Use Object-Oriented Programming in the First Place?

Software Development

n HW5 out, due Tuesday October 30 th n Part 1: Questions on material we ll cover today n Part 2: BFS using your graph from HW4

SOLID: Principles of OOD

Design Principles: Part 2

Design Principles: Part 2

Outline. Design Principles: Part 2. e.g. Rectangles and Squares. The Liskov Substitution Principle (LSP) ENGI 5895: Software Design.

COURSE 2 DESIGN PATTERNS

Object-Oriented Concepts and Design Principles

Agile Principles, Patterns, and Practices in C#

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Object-Oriented Systems Analysis and Design Using UML

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

09. Component-Level Design

Lecture Notes on Programming Languages

User Interface Design. Slides copyright 1996, 2001, 2005, 2009, 2014 by Roger S. Pressman. For non-profit educational use only

Inheritance and object compatibility

(Movement - Synthesis) Improve existing programming skills by developing much larger and more complex programs than in previous classes.

More on object orientation

Bruno Bossola SOLID Design Principles

A Java Execution Simulator

Object Oriented Software Design - I

Highlights of Previous Lecture

Software Testing Strategies. Software Engineering: A Practitionerʼs Approach, 7/e by Roger S. Pressman

The Liskov Substitution Principle

Object- Oriented Design with UML and Java Part I: Fundamentals

May Comp-B 11, Advanced Software Design. 3 hours duration

Inheritance (Chapter 7)

OO Technology: Properties and Limitations for Component-Based Design

OO Design Principles

Build Testable Client and Service Applications

Lecture 8: Chapter 8!

PROCESS DEVELOPMENT METHODOLOGY The development process of an API fits the most fundamental iterative code development

Programming 2. Object Oriented Programming. Daniel POP

Object-Oriented Design

1. Write two major differences between Object-oriented programming and procedural programming?

11/4/15. Review. Objec&ves. Refactoring for Readability. Review. Liskov Subs&tu&on Principle (LSP) LISKOV SUBSTITUTION PRINCIPLE

Princípy tvorby softvéru Dizajnové princípy

GRASP Design Patterns A.A. 2018/2019

Principles of Object-Oriented Design

Last Time: Object Design. Comp435 Object-Oriented Design. Last Time: Responsibilities. Last Time: Creator. Last Time: The 9 GRASP Patterns

Object-oriented design principles

Object-Oriented Genetic Improvement for Improved Energy Consumption in Google Guava

PDF/A - The Basics. From the Understanding PDF White Papers PDF Tools AG

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt

Back to ObjectLand. Contents at: Chapter 5. Questions of Interest. encapsulation. polymorphism. inheritance overriding inheritance super

Originality is Overrated: OO Design Principles

Software Engineering Fall 2015 (CSC 4350/6350) TR. 5:30 pm 7:15 pm. Rao Casturi 11/03/2015

Influence of Design Patterns Application on Quality of IT Solutions

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programmazione. Prof. Marco Bertini

EasyChair Preprint. Software Metrics Proposal for Conformity Checking of Class Diagram to SOLID Design Principles

Programmazione. Prof. Marco Bertini

Software Design And Modeling BE 2015 (w. e. f Academic Year )

Tecniche di Progettazione: Design Patterns

e t O b O j b e j c e t c i t v i e v s e Volume 1, Issue 4 April 2004 The Principles and Strategies of Design Patterns In This Issue: Overview

Object Oriented Programming

SOLID Design for Embedded C

CSC207 Week 3. Larry Zhang

Principles of Software Construction: Objects, Design and Concurrency. Object-Oriented Design: Assigning Responsibilities.

Component-Level Design. Slides copyright 1996, 2001, 2005, 2009 by Roger S. Pressman (revised by Seung- Hoon Na) For non-profit educational use only

[ L5P1] Object-Oriented Programming: Advanced Concepts

PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 10. PUTTING IT ALL TOGETHER. Are we there yet?

Design by Contract: An Overview

Study of Component Based Software Engineering

Transcription:

CHAPTER 5: PRINCIPLES OF DETAILED DESIGN SESSION II: STRUCTURAL AND BEHAVIORAL DESIGN OF COMPONENTS Software Engineering Design: Theory and Practice by Carlos E. Otero Slides copyright 2012 by Carlos E. Otero For non-profit educational use only May be reproduced only for student use when used in conjunction with Software Engineering Design: Theory and Practice. Any other reproduction or use is prohibited without the express written permission of the author. All copyright information must appear if these slides are posted on a website for student use. 10/3/2012 Software Engineering Design: Theory and Practice 1

SESSION S AGENDA Overview of Component Design Designing Internal Structure of Components (OO Approach) Classes and objects Interfaces, types, and subtypes Dynamic binding Polymorphism Design Principles for Internal Component Design The open-closed principle The Liskov Substitution principle The interface segregation principle Designing Internal Behavior of Components What s next 10/3/2012 Software Engineering Design: Theory and Practice 2

OVERVIEW OF COMPONENT DESIGN Component design (also referred as component-level design) refers to the detailed design task of defining the internal logical structure and behavior of components. That is, refining the structure of components identified during the software architecture activity. In OO, the internal structure of components identified during architecture can be designed as a single class, numerous classes, or sub components. Consider the following components and interface identified during architecture During Architecture During the component design task of the detailed design activity, these components are refined to fully define how they realize the component s services Important: In OO, during detailed design, we shift away from the more abstract UML component and begin to think in terms of classes, interfaces, types, etc. During Detailed Design This is the same as that Not quite enough details, but you get the idea, right? 10/3/2012 Software Engineering Design: Theory and Practice 3

OVERVIEW OF COMPONENT DESIGN In object-oriented systems, the internal structure of components is typically modeled using UML through one or more class diagrams. During component design, the internal data structures, algorithms, interface details, and communication mechanisms for all components are defined. For this reason, structural and behavioral modes created as part of detailed design provide the most significant mechanism for determining the functional correctness of the software system. This allows us to evaluate alternative solutions before construction begins. The work produced during component design contributes significantly to the functional success of the system. In OO, before we can become expert component designers, we must understand the following: Classes and objects Interfaces, types, and subtypes Dynamic binding Polymorphism 10/3/2012 Software Engineering Design: Theory and Practice 4

Conceptual View of the Process OVERVIEW OF COMPONENT DESIGN Software Architect Here s a component This guy is also a Software Engineer Requirements document Software Engineer All I need is one class, let me generate the code from the class design Component designed to meet some system service Class designed to realize the component s services Code generated from the class specification Binary file is generated from code compilation and build process. Binary file is executed 10/3/2012 Software Engineering Design: Theory and Practice 5

In previous modules, we introduced the concept of quality and discussed several important ones, such as modifiability, performance, etc. Let s focus on modifiability; what does this mean at the detailed design level? Minimizing the degree of complexity involved when changing the system to fit current or future needs. This is hard when working with the level of detail that is required during the detailed design activity! Modifiability cannot be met alone with sound architectural designs; detailed design is crucial to meet this quality attribute. Component designs that evolve gracefully over time are hard to achieve. Therefore, when designing software at the component-level, several principles have to be followed to create designs that are reusable, easier to modify, and easier to maintain. OO Design principles for internal component design include: The Open-Closed Principle The Liskov Substitution Principle The Dependency-Inversion Principle The Interface-Segregation Principle 10/3/2012 Software Engineering Design: Theory and Practice 6

THE OPEN-CLOSED PRINCIPLE (OCP) The Open-Closed principle (OCP) is an essential principle for creating reusable and modifiable systems that evolve gracefully with time. The OCP was originally coined by Bertrand Meyer [1] and it states that software designs should be open to extension but closed for modification. The main idea behind the OCP is that code that works should remain untouched and that new additions should be extensions of the original work. That sounds contradictory, how can that be? Being close to modifications does not mean that designs cannot be modified; it means that modifications should be done by adding new code, and incorporating this new code in the system in ways that does not require old code to be changed! 10/3/2012 Software Engineering Design: Theory and Practice 7

THE OPEN-CLOSED PRINCIPLE (OCP) Consider a fictional gaming system that includes several types of terrestrial characters, ones that can roam freely over land. It is anticipated that new characters will be added in the future. Note: This is really not the code for a gaming system! The code is for illustration purpose. What can you tell me about the add( ) function? What happens if we add a new requirement to support other types of characters, e.g., an AerialCharacter that can fly? Yes, that is right, we would have to change the code inside the add( ) method. This violates the OCP! Let s see an improved version in the next slide 10/3/2012 Software Engineering Design: Theory and Practice 8

THE OPEN-CLOSED PRINCIPLE (OCP) Too easy! I ll just create a base Character and have both terrestrial and aerial characters derive from it. Done! Joe Developer decided to abstract the Character concept and separate it from more specific Character types Inherits from Character Inherits from Character Joe Developer Since Terrestrial characters run and Aerial ones fly, Joe decided to delegate creation of these functions to subtypes, namely, TerrestrialCharacter and AerialCharacter Are we done? Not really! The gettype( ) function should give you an indication why we re still violating the OCP. Let s take a closer look in the next slide Note: Character is really an interface, so instead of Inherits from Character it (more precisely) realizes the Character inter terface. 10/3/2012 Software Engineering Design: Theory and Practice 9

THE OPEN-CLOSED PRINCIPLE (OCP) Design Principle: Encapsulate Variation This code will always vary, depending on the characters in the game! Sample test driver code Notice how the GameEngine client needs to know the type of Character before it can activate it. This is a side- effect of a violation of the OCP Sample output Yikes! The Character design still requires clients to know too much about Characters. What would happen if we now need to support an Aquatic Character? It works! We re done! Not really, we ve improved the design, but are we OCP-Compliant? Compliant? Let s see in the next slide how to make this design OCP-Compliant Compliant 10/3/2012 Software Engineering Design: Theory and Practice 10

THE OPEN-CLOSED PRINCIPLE (OCP) Encapsulate the movement behavior, so that move( ) works for all characters in the game! Per the interface contract, these must provide the implementation for both draw and fly services In the next slide, let s see how the code for the GameEngine class looks now based on this new design 10/3/2012 Software Engineering Design: Theory and Practice 11

THE OPEN-CLOSED PRINCIPLE (OCP) New redesign! Adheres to OCP! Old design! Violates OCP! New Aquatic Character added by extension and not by modifying existing working code! With this design, GameEngine can draw and activate current and future Characters in the game without modification! 10/3/2012 Software Engineering Design: Theory and Practice 12

THE OPEN-CLOSED PRINCIPLE (OCP) One final note about the OCP: No design will be 100% closed for modification. At some point, some code has to be readily-available available for tweaking in any software system. The idea of the OCP is to locate the areas of the software that are likely to vary and the variations can be encapsulated and implemented through polymorphism. 10/3/2012 Software Engineering Design: Theory and Practice 13

THE LISKOV SUBSTITUTION PRINCIPLE (LSP) The LSP was originally proposed by Barbara Liskov and serves as basis for creating designs that allows clients that are written against derived classes to behave just as they would have if they were written using the corresponding base classes. The LSP requires Signatures between base and derived classes to be maintained Subtype specification supports reasoning based on the super type specification In simple terms, LSP demands that "any class derived from a base class must honor any implied contract between the base class and the components that use it. [2] To adhere to the LSP, designs must conform to the following rules: The Signature Rule The Methods Rule 10/3/2012 Software Engineering Design: Theory and Practice 14

THE LISKOV SUBSTITUTION PRINCIPLE (LSP) The Signature Rule ensures that if a program is type-correct based on the super type specification, it is also type-correct with respect to the subtype specification. The Method Rule ensures that reasoning about calls of super type methods is valid even though the calls actually go to code that implements a subtype. Subtype methods can weaken pre-conditions, not strengthen them (i.e., require less, not more). Subtype methods can strengthen post-conditions, not weaken them (i.e., provide more, not less). 10/3/2012 Software Engineering Design: Theory and Practice 15

INTERFACE SEGREGATION PRINCIPLE (ISP) Well designed classes should have one (and only one) reason to change. The interface segregation principle (ISP) states that "clients should not be forced to depend on methods that they do not use [3]. Consider a gaming system that supports an advanced enemy character that is able to roam over land, fly, and swim. The game also supports other enemy characters that can either roam over land, fly, or swim. Some would be tempted to design the system as seen below. Bloated interface! 10/3/2012 Software Engineering Design: Theory and Practice 16

INTERFACE SEGREGATION PRINCIPLE (ISP) The ISP implies that many client-specific interfaces are better than one general purpose interface Smaller, specific interfaces are easier to maintain and reuse and lead to easier adherence to OCP and LSP 10/3/2012 Software Engineering Design: Theory and Practice 17

MODELING INTERNAL BEHAVIOR OF COMPONENTS 10/3/2012 Software Engineering Design: Theory and Practice 18

MODELING INTERNAL BEHAVIOR OF COMPONENTS Common interaction operators used in sequence diagrams include: 10/3/2012 Software Engineering Design: Theory and Practice 19

WHAT S NEXT In this session, we presented fundamentals concepts of the component design, including: Overview of Component Design Designing Internal Structure of Components (OO Approach) Classes and objects Interfaces, types, and subtypes Dynamic binding Polymorphism Design Principles for Internal Component Design The open-closed principle The Liskov Substitution principle The interface segregation principle Designing Internal Behavior of Components In the next module, we will present in detail the concept of design patterns, which include : Creational Behavioral Structural 10/3/2012 Software Engineering Design: Theory and Practice 20

REFERENCES [1] Meyer, Bertrand. Object-oriented Software Construction, 2d ed. Upper Saddle River, NJ: Prentice Hall, 1997. [2] Pressman, Roger S. Software Engineering: A Practitioner s Approach, 7 th ed. Chicago: McGraw-Hill, 2010. [3] Marin, Robert C. Agile Software Development: Principles, Patterns, and Practices. Upper Saddle River, NJ: Prentice Hall, 2003. 10/3/2012 Software Engineering Design: Theory and Practice 21