Object-Oriented Design

Similar documents
Object-Oriented Design

17. GRASP: Designing Objects with Responsibilities

GRASP Design Patterns A.A. 2018/2019

Patterns and Testing

ADVANCED SOFTWARE DESIGN LECTURE 7 GRASP

Software Engineering

Object-Oriented Design II - GRASP

Summary of the course lectures

Information Expert (or Expert)

ADVANCED SOFTWARE DESIGN LECTURE 4 GRASP. Dave Clarke

Eliminate enterprise software design instability - protect variations! Nickolay Kofanov

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

Object-Oriented Design I

CHAPTER 5: PRINCIPLES OF DETAILED DESIGN

GRASP: Patterns for. chapter18

GRASP 2. CSC 440: Software Engineering Slide #1

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

Object-Oriented Design I - SOLID

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

Assigning Responsibilities (Patterns of Responsibility Assignment Principles: GRASP)

Tecniche di Progettazione: Design Patterns

OODP OOAD Session 7a

Final Exam. Final Exam Review. Ch 1: Introduction: Object-oriented analysis, design, implementation. Exam Format

Object Analysis & Design in the textbook. Introduction to GRASP: Assigning Responsibilities to Objects. Responsibility-Driven Design

Principles of Software Construction: Objects, Design, and Concurrency. Assigning Responsibilities to Objects. toad. Jonathan Aldrich Charlie Garrod

2009 Shawn A. Bohner. Shawn Bohner Office: Moench Room F212 Phone: (812)

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

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

SOLID Principles. Equuleus Technologies. Optional Subheading October 19, 2016

Four More GRASP Principles CSSE 574: Session 5, Part 2

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

From Design Patterns: Elements of Reusable Object Oriented Software. Read the sections corresponding to patterns covered in the following slides.

OODP Session 5a. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

Responsibilities. Using several specific design principles to guide OO design decisions.

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

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

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

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

Assertions. Assertions - Example

ADVANCED SOFTWARE DESIGN LECTURE 4 SOFTWARE ARCHITECTURE

Design patterns. Jef De Smedt Beta VZW

COURSE 2 DESIGN PATTERNS

Principles of Object-Oriented Design

17.11 Bean Rules persistent

References: Applying UML and patterns Craig Larman

Design by Contract in Eiffel

GRASP: MORE PATTERNS FOR

2 GRASP Patterns and basic OO Design. Roel Wuyts OASS

BCS Higher Education Qualifications. Diploma in IT. Object Oriented Programming Syllabus

OO Design Principles

GRASP ing at the First 5 Patterns Principles CSSE 574: Session 3, Part 4

CMPS 115 Winter 04. Class #10 (2004/02/05) Changes/Review Programming Paradigms Principles of OOD <break> Design Patterns

Object-Oriented Design II

09. Component-Level Design

COMP 6471 Software Design Methodologies

Chapter 1: Principles of Programming and Software Engineering

Appendix A - Glossary(of OO software term s)

Object-Oriented Design

a correct statement? You need to know what the statement is supposed to do.

Software Engineering

CSE 70 Final Exam Fall 2009

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

CMPE/SE 135 Object-Oriented Analysis and Design

References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 10/14/2004 1

Review Software Engineering October, 7, Adrian Iftene

11/2/09. Code Critique. What goal are we designing to? What is the typical fix for code smells? Refactoring Liskov Substitution Principle

C++ Modern and Lucid C++ for Professional Programmers

The following topics will be covered in this course (not necessarily in this order).

Software Design and Analysis CSCI 2040

Granularity. Inheritance Bi-directional. Association. Derived A1

COMP 6471 Software Design Methodologies

Agile Software Development

Influence of Design Patterns Application on Quality of IT Solutions

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Applying Design Patterns to accelerate development of reusable, configurable and portable UVCs. Accellera Systems Initiative 1

Object Relationships

OO Class Design Principles

Lecture 17: Patterns Potpourri. Copyright W. Howden 1

Object Oriented. Analysis and Design

Object-Oriented Design

Assigning Responsibilities by Larman

VEL TECH HIGH TECH Dr. RANGARAJAN Dr. SAKUNTHALA ENGINEERING COLLEGE UNIT 1 UML DIAGRAMS

Chapter 1: Programming Principles

340 Review Fall Midterm 1 Review

Lecture Notes: Hoare Logic

Object-Oriented Concepts and Design Principles

Object-Oriented Analysis and Design

MSO Lecture Design by Contract"

Component-Level Design

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

Why Design by Contract! CS 619 Introduction to OO Design and Development. Design by Contract. Fall 2012

CS342: Software Design. November 21, 2017

Top Down Design vs. Modularization

EINDHOVEN UNIVERSITY OF TECHNOLOGY

Assigning Responsibilities

Design Principles: Part 2

Inheritance (Chapter 7)

Lecture: Modular Design

Object-Oriented Design

Object Oriented Program Correctness with OOSimL

Transcription:

Object-Oriented Design Lecturer: Raman Ramsin Lecture 15: Object-Oriented Principles 1

Open Closed Principle (OCP) Classes should be open for extension but closed for modification. OCP states that we should be able to add new features to our system without having to modify our set of preexisting classes. One of the tenets of OCP is to reduce the coupling between classes to the abstract level. Instead of creating relationships between two concrete classes, we create relationships between a concrete class and an abstract class or an interface. 2

Liskov Substitution Principle (LSP) Subclasses should be substitutable for their base classes. Also called the substitutability principle. 3

Dependency Inversion Principle (DIP) Depend upon abstractions. Do not depend upon concretions. The Dependency Inversion Principle (DIP) formalizes the concept of abstract coupling and clearly states that we should couple at the abstract level, not at the concrete level. DIP tells us how we can adhere to OCP. 4

Interface Segregation Principle (ISP) Many specific interfaces are better than a single, general interface. Any interface we define should be highly cohesive. 5

Composite Reuse Principle (CRP) Favor polymorphic composition of objects over inheritance. One of the most catastrophic mistakes that contribute to the demise of an object-oriented system is to use inheritance as the primary reuse mechanism. Delegation can be a better alternative to Inheritance. 6

Principle of Least Knowledge (PLK) For an operation O on a class C, only operations on the following objects should be called: itself, its parameters, objects it creates, or its contained instance objects. Also called the Law of Demeter. The basic idea is to avoid calling any methods on an object where the reference to that object is obtained by calling a method on another object (Transitive Visibility). The primary benefit is that the calling method doesn t need to understand the structural makeup of the object it s invoking methods upon. 7

GRASP Acronym stands for General Responsibility Assignment Software Patterns. A set of 9 Patterns introduced as a learning aid by Craig Larman. Describe fundamental principles for object-oriented design and responsibility assignment, expressed as patterns. The skillful assignment of responsibilities is extremely important in object design. Determining the assignment of responsibilities often occurs during the creation of interaction diagrams, and certainly during programming. 8

GRASP: Patterns 1. Information Expert 2. Creator 3. Low Coupling 4. High Cohesion 5. Controller 6. Polymorphism 7. Indirection 8. Pure Fabrication 9. Protected Variations 9

GRASP: Information Expert As a general principle of assigning responsibilities to objects, assign a responsibility to the information expert: i.e. the class that has the information necessary to fulfill the responsibility. 10

GRASP: Creator Assign class B the responsibility to create an instance of class A if one or more of the following is true: B aggregates A objects. B contains A objects. B records instances of A objects. B closely uses A objects. B has the initializing data that will be passed to A when it is created (thus B is an Expert with respect to creating A). B is a creator of A objects. If more than one option applies, prefer a class B which aggregates or contains class A. 11

GRASP: Low Coupling Assign a responsibility so that coupling remains low. A class with high (or strong) coupling relies on many other classes. Such classes may be undesirable; some suffer from the following problems: Changes in related classes force local changes. Harder to understand in isolation. Harder to reuse because its use requires the additional presence of the classes on which it is dependent. 12

GRASP: High Cohesion Assign a responsibility so that cohesion remains high. A class with low cohesion does many unrelated things, or does too much work. Such classes are undesirable; they suffer from the following problems: hard to comprehend hard to reuse hard to maintain Delicate: constantly affected by change 13

GRASP: Controller Assign the responsibility for receiving or handling a system event message to a class representing one of the following choices: Represents the overall system, device, or subsystem (facade controller). Represents a use case scenario within which the system event occurs (a use-case- or session-controller). Use the same controller class for all system events in the same use case scenario. Informally, a session is an instance of a conversation with an actor. Note that "window," "applet," "widget," "view," and "document" classes are not on this list. Such classes should not fulfill the tasks associated with system events, they typically delegate these events to a controller. 14

GRASP: Polymorphism When related alternatives or behaviors vary by type (class), assign responsibility for the behavior using polymorphic operations to the types for which the behavior varies. Define the behavior in a common base class or, preferably, in an interface. 15

GRASP: Indirection Assign the responsibility to an intermediate object to mediate between other components or services so that they are not directly coupled. The intermediary creates an indirection between the other components. Beware of transitive visibility. 16

GRASP: Pure Fabrication Assign a highly cohesive set of responsibilities to an artificial or convenience class that does not represent a problem domain concept something made up, to support high cohesion, low coupling, and reuse. Example: a class that is solely responsible for saving objects in some kind of persistent storage medium, such as a relational database; call it the PersistentStorage. This class is a Pure Fabrication a figment of the imagination. 17

GRASP: Protected Variations Identify points of predicted variation or instability; assign responsibilities to create a stable interface around them. Note: The term "interface" is used in the broadest sense of an access view; it does not literally only mean something like a Java or COM interface. 18

Design by Contract (DBC) A discipline of analysis, design, implementation, and management. Bertrand Meyer introduced Design by Contract in Eiffel as a powerful technique for producing reliable software. Its key elements are assertions: boolean expressions that define correct program states at arbitrary locations in the code. 19

Design by Contract (DBC): Assertions Simple assertions belong to individual statements in a program, yet important DBC assertions are defined on classes: Per- method assertions: Precondition: A condition that must be true of the parameters of a method and/or data members if the method is to behave correctly PRIOR to running the code in the method. Postcondition: A condition that is true AFTER running the code in a method. Per-class assertions: Class Invariant: A condition that is true BEFORE and AFTER running the code in a method (except constructors and destructors). 20

Design by Contract (DBC): Contract Assertions in a class specify a contract between its instances and their clients. According to the contract a server promises to return results satisfying the postconditions if a client requests available services and provides input data satisfying the preconditions. Invariants must be satisfied before and after each service. Neither party to the contract (the clients/consumers and servers/suppliers) shall be allowed to rely on something else than that which is explicitly stated in the contract. 21

Design by Contract (DBC): Inheritance The class invariants of all ancestors must also be obeyed by all children; they can also be strengthened. Inherited preconditions may only be weakened. This means a new implementation may never restrict the circumstances under which a client call is valid beyond what has been specified by the ancestor. It may, however, relax the rules and also accept calls that would have been rejected by the ancestor. Inherited postconditions may only be strengthened. This means a new implementation must fulfil what the ancestors have undertaken to do, but may deliver more. "Children should not provide less or expect more than their ancestors." 22

Reference Larman, C., Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development, 3 rd Ed. Prentice-Hall, 2004. 23