Object-Oriented Design I - SOLID

Similar documents
Object-Oriented Design I

Object-Oriented Design II - GRASP

Object-Oriented Design II

Software Engineering

Object-Oriented Design

GRASP Design Patterns A.A. 2018/2019

CSC207H: Software Design SOLID. CSC207 Winter 2018

Eliminate enterprise software design instability - protect variations! Nickolay Kofanov

Design patterns. Jef De Smedt Beta VZW

Object-Oriented Design

COURSE 2 DESIGN PATTERNS

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

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

Tecniche di Progettazione: Design Patterns

Patterns and Testing

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

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

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

S.O.L.I.D: Software Engineering Principles

Open Closed Principle (OCP)

CS 520 Theory and Practice of Software Engineering Fall 2018

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

CS 520 Theory and Practice of Software Engineering Fall 2017

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

Highlights of Previous Lecture

Inheritance and object compatibility

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

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

Software Design and Analysis CSCI 2040

Resolving Cyclic Dependencies Design for Testability

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

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

Single Responsibility Principle (SRP)

Chapter 5 Object-Oriented Programming

Recap: Class Diagrams

Configuration Provider: A Pattern for Configuring Threaded Applications

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

CS 320 Introduction to Software Engineering Spring March 06, 2017

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

17. GRASP: Designing Objects with Responsibilities

Infor Education. Mongoose Workshop. Infor Education. Mongoose Workshop. Class 3: Data and Its Representation and Organization.

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

SOLID: Principles of OOD

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

Design Engineering. Overview

Principles of Object-Oriented Design

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

ADVANCED SOFTWARE DESIGN LECTURE 7 GRASP

CS 520 Theory and Practice of Software Engineering Fall 2018

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

Design Principles: Part 2

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

OO Design Principles

A - 1. CS 494 Object-Oriented Analysis & Design. UML Class Models. Overview. Class Model Perspectives (cont d) Developing Class Models

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

Design Principles: Part 2

Software Development Project. Kazi Masudul Alam

Intro to: Design Principles

CS 320 Introduction to Software Engineering Spring March

HAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A.

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

ADVANCED SOFTWARE DESIGN LECTURE 4 GRASP. Dave Clarke

CSCU9T4: Managing Information

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

Chapter 10 Object-Oriented Design Principles

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

Overview of Java s Support for Polymorphism

Design Engineering. Dr. Marouane Kessentini Department of Computer Science

[ L5P1] Object-Oriented Programming: Advanced Concepts

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

Introduction to Object-Oriented Programming

CS 215 Software Design Sample Midterm Questions

GRASP 2. CSC 440: Software Engineering Slide #1

CO Java SE 8: Fundamentals

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

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

Example: Count of Points

Unified Modeling Language (UML) Class Diagram

Appendix A - Glossary(of OO software term s)

Computer Science II (20073) Week 1: Review and Inheritance

CSC207 Week 3. Larry Zhang

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

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

Software Specifications. CMSC 433 Programming Language Technologies and Paradigms Spring Specifications Help You Write Code

First IS-A Relationship: Inheritance

Web Architecture and Development

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

OODP OOAD Session 7a

COMP 6471 Software Design Methodologies

The major elements of the object-oriented model

Exam in TDDB84: Design Patterns,

17.11 Bean Rules persistent

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

CHAPTER 5: PRINCIPLES OF DETAILED DESIGN

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

Unit Testing Activity

Software Engineering

Superclasses / subclasses Inheritance in Java Overriding methods Abstract classes and methods Final classes and methods

CISC 3115 Modern Programming Techniques Spring 2018 Section TY3 Exam 2 Solutions

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

Transcription:

Object-Oriented Design I - SOLID SWEN-261 Introduction to Software Engineering Department of Software Engineering Rochester Institute of Technology Single responsibility Open/close Liskov substitution Interface segregation 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 these principles 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 We will look at SOLID today. 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. Similar to how we separated responsibilities into tiers at the architectural level. Helps with unit testing. 4

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. 5

Make a class as simple as possible, but not simpler. 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. 6

Some model 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 the model tier. You could consider this to be only a data holder class with no other behavior. This would lead to something like 7

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() Your Flight class should provide: boolean originis(string airportcode) boolean destinationis(string airportcode) boolean itineraryis(string origincode, String destinationcode) boolean arrivesnextday() boolean canconnectwith(flight flt, unsigned int minconnecttime) 8

The Open/closed principle deals with extending and protecting functionality. Software entities should be open for extension, but closed for modification. Software functionality should be extendable without modifying the base functionality. Mostly provided by features of implementation language: inheritance, interface Your design should consider appropriate use of Inheritance from abstract classes Implementation of interfaces Most design patterns provide extension points SWEN-262 Engineering of Software Subsystems 9

The Liskov substitution principle constrains the pre- and post-conditions of operations. Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program Pre-conditions specify what must be true before a method call. Post-conditions specify what will be true after a method call. A subclass method should not have narrower preconditions, or broader post-conditions than the superclass method it overrides. 10

Here are what Liskov substitution allows. method1() must accept at least params of 1 through 10. It could accept a wider range, i.e. 1 to 15. If client reference is to: SuperClass SubClass method1() can not quadruple the value of the parameter because that would lead to a broader post-condition, i.e. attribute between 4 and 40. It could have a narrower post-condition of 3 to 17, i.e. it does +2 to the parameter. 11

The Interface segregation principle allows a client to depend only on the methods it needs to use. Many client-specific interfaces are better than one general-purpose interface. Break up interfaces and abstract classes into smaller units so a client only needs to know about methods it uses. The Single responsibility principle helps to achieve this. 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 high-level module injects into the low-level module the element it is dependent on. Both are dependent only on the abstraction (highlevel) not the implementation details (low-level), an inversion of the typical dependency. 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 objects.

There was dependency injection in the sample webapp. public static void main(string[] args) { snip // create the one and only game center final GameCenter gamecenter = new GameCenter(); // The application uses FreeMarker templates to generate the HTML // responses sent back to the client. This will be the engine processing // the templates and associated data. final TemplateEngine templateengine = new FreeMarkerEngine(); // inject the game center and freemarker engine into web server final WebServer webserver = new WebServer(gameCenter, templateengine); // inject web server into application final Application app = new Application(webServer); } // start the application up app.initialize(); 14