Object-Oriented Design I

Similar documents
Object-Oriented Design II - GRASP

Object-Oriented Design I - SOLID

Object-Oriented Design II

GRASP Design Patterns A.A. 2018/2019

Object-Oriented Design

Object-Oriented Design

Eliminate enterprise software design instability - protect variations! Nickolay Kofanov

CSC207H: Software Design SOLID. CSC207 Winter 2018

Design patterns. Jef De Smedt Beta VZW

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

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas

ADVANCED SOFTWARE DESIGN LECTURE 7 GRASP

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

Dependency Inversion, Dependency Injection and Inversion of Control. Dependency Inversion Principle by Robert Martin of Agile Fame

Tecniche di Progettazione: Design Patterns

Patterns and Testing

References: Applying UML and patterns Craig Larman

Avancier Methods. Very basic design patterns. It is illegal to copy, share or show this document

Software Engineering

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

17. GRASP: Designing Objects with Responsibilities

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

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

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

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

COURSE 2 DESIGN PATTERNS

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

ADVANCED SOFTWARE DESIGN LECTURE 4 GRASP. Dave Clarke

Application Architectures, Design Patterns

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

CAS 703 Software Design

Software Design and Analysis CSCI 2040

02291: System Integration

SE310 Analysis and Design of Software Systems

Introduction to Testing and Maintainable code

1 Software Architecture

A4 Explain how the Visitor design pattern works (4 marks)

Information Expert (or Expert)

COMP 6471 Software Design Methodologies

Build Testable Client and Service Applications

Final Exam CISC 475/675 Fall 2004

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

Applying Some Gang of Four Design Patterns CSSE 574: Session 5, Part 3

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

SOLID: Principles of OOD

OODP OOAD Session 7a

Software Engineering

Agile Architecture. The Why, the What and the How

Software Engineering Principles

Lessons Learned. Johnny Bigert, Ph.D., Skype/Microsoft October 26, 2011

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

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

Software Design and Analysis CSCI 2040

CS 575: Software Design

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

GRASP: MORE PATTERNS FOR

GRASP 2. CSC 440: Software Engineering Slide #1

Single Responsibility Principle (SRP)

Advanced Object Oriented Design Laboratory.

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

Chapter 8: Class and Method Design

Recap: Class Diagrams

Topics. Software Process. Agile. Requirements. Basic Design. Modular Design. Design Patterns. Testing. Quality. Refactoring.

Object Oriented. Analysis and Design

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

Produced by. Agile Software Development. Eamonn de Leastar

Database Design. 6-2 Normalization and First Normal Form. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Lecture: Modular Design

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

Chapter 10 Object-Oriented Design Principles

The de constructed. Magento module

CHAPTER 5: PRINCIPLES OF DETAILED DESIGN

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

Design Patterns Thinking and Architecture at Scale

CSCU9T4: Managing Information

Design Engineering. Overview

Single Responsibility Principle

The object-oriented approach goes a step further by providing tools for the programmer to represent elements in the problem space.

OBJECT ORIENTED ANALYSIS AND DESIGN SYLLABUS

Highlights of Previous Lecture

Test Driven Development (TDD)

Domain Analysis. SWEN-261 Introduction to Software Engineering. Department of Software Engineering Rochester Institute of Technology.

THE OBJECT-ORIENTED DESIGN PROCESS AND DESIGN AXIOMS (CH -9)

The Object-Oriented Paradigm

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

Principles of Object-Oriented Design

MSO Object Creation Singleton & Object Pool

Resolving Cyclic Dependencies Design for Testability

Review Software Engineering October, 7, Adrian Iftene

SELECTED TOPICS in APPLIED COMPUTER SCIENCE

Compsci 290/Mobile, Java

Intro to: Design Principles

Patterns Of Enterprise Application Architecture (Addison-Wesley Signature Series (Fowler)) PDF

17.11 Bean Rules persistent

CTIS 359 Principles of Software Engineering SOFTWARE DESIGN OO(A)D

Software Design Heuristics

The Challenge. Principles of Software Design

OBJECT-ORIENTED DOMAIN DRIVEN DESIGN. Robert Bräutigam MATHEMA So ware GmbH.

Maintainable Software. Software Engineering Andreas Zeller, Saarland University

Exam in TDDB84: Design Patterns,

Transcription:

Object-Oriented Design I SWEN-261 Introduction to Software Engineering Department of Software Engineering Rochester Institute of Technology Single responsibility High cohesion Information expert Low coupling Law of Demeter Dependency inversion

Up to this point, you have studied object-oriented design mostly at the class level. This set of skills needs to be expanded to design larger scale systems. You need to consider the interactions between classes and the effect of classes on other classes. The software engineering community has put forward sets of design principles to follow. SOLID (Bob Martin, Principles of OOD) GRASP (Craig Larman, Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development.) We will look at some of these principles, along with the Law of Demeter, in two lessons. 2

SOLID and GRASP provide two sets of object-oriented design principles. SOLID Single responsibility Open/closed Liskov substitution Interface segregation Dependency inversion Law of Demeter GRASP Controller Creator Indirection Information expert High cohesion Low coupling Polymorphism Protected variations Pure fabrication 3

The Single responsibility principle is perhaps the most important object-oriented design principle. A class should have only a single responsibility. A class should have a single, tightly focused responsibility. This leads to smaller and simpler classes, but more of them. Easier to understand the scope of a change in a class. Easier to manage concurrent modifications. Separate concerns go into separate classes. Helps with unit testing. 4

High Cohesion aims for focused, understandable, and manageable classes. Assign responsibility so the cohesion of classes remains high. High cohesion leads to smaller classes with more narrowly defined responsibilities. This should be high on your list of design goals. High cohesion will require coupling to more classes to get work accomplished. Do not be afraid of requiring a few more relationships in the pursuit of improved cohesion. 5

Consider that you are implementing a library management system. You could place most of the functionality into a LibraryManager class. This class would have too many responsibilities. Maintaining the library catalog Maintaining patron accounts Scheduling library events Separate the concerns into more classes each with a single highly focused responsibility. 6

Make a class as simple as possible, but not simpler. Everything should be made as simple as possible, but not simpler. - Einstein Aim to implement the behaviors that directly work with the class' attributes. Consider what clients will want to do with the attribute data put those behaviors in the class. If you are a client doing processing with the attribute data, consider putting your operation in the class. 7

Some classes are more complex than you think they are. Consider that you are building an airline flight reservation system. A Flight entity will definitely be in the domain model and be a class in your implementation. You could consider this to be only a data holder class with no other behavior. This would lead to something like 8

Student project code often does not do right by the client of their classes. Note: Time is stored in 24 hour notation. A client of Flight had this code: flt.getdestination().equals("jfk") flt1.getorigin().equals("roc") && flt1.getdestination().equals("jfk") flt.getarrival() < flt.getdeparture() flt1.getarrival() + 60 < flt2.getdeparture() Why does the client of Flight have to do this "heavy-lifting"? 9

Information Expert looks to have behavior follow data. 10 Assign responsibility to the class that has the information needed to fulfill the responsibility. The first place to consider placing behavior that uses/processes attribute data is in the class that holds the attributes. Instead of the client of Flight implementing this: flt.getdestination().equals("jfk") flt1.getorigin().equals("roc") && flt1.getdestination().equals("jfk") flt.getarrival() < flt.getdeparture() flt1.getarrival() + 60 < flt2.getdeparture() Consider Flight as the Information expert boolean Flight.originIs(String airportcode) boolean Flight.destinationIs(String airportcode) boolean Flight.itineraryIs(String origincode, String destinationcode) boolean Flight.arrivesNextDay() boolean Flight.canConnectWith(Flight nextflight)

Low Coupling attempts to minimize the impact of changes in the system. Assign responsibility so that (unnecessary) coupling remains low. Note the unnecessary word. Coupling is needed in your system. Resist lowering coupling simply to reduce the number of relationships. A design with more relationships is often better than the design with fewer relationships. You need to balance all the design principles. Beginning designers often place low coupling at the top of their design principles list. It should be lower down! 11

The Law of Demeter addresses unintended coupling within a software system. Limit the range of classes that a class talks to Each unit only talks to its friends; don't talk to strangers. Each unit only talks to its immediate friends; don't talk to friends of friends Chained access exposes each intermediate interface From a previous checkers project board.getpieceat(i,j).gettype() eliminate violation of Law of Demeter and reduce coupling for this class, i.e. may not need to know about Piece board.getpiecetypeat(i,j) or predicate If you need to talk to something "far away" Get support from your friend, i.e. new method Get a new friend, i.e. new direct relationship 12

The Dependency inversion principle provides looser coupling between dependent entities. 13 High-level modules should not depend on low-level modules. Both should depend on abstractions. A common manifestation of this is dependency injection. The low-level module does not have responsibility for instantiating a specific dependent class. The high-level module injects the dependent element. The low-level module is only dependent on the (highlevel) abstraction not the (low-level) implementation. The injection can be during construction, using a setter, or as a parameter in an operation method. Critical for doing unit testing since we can inject test/mock objects.