Object-oriented metrics Design decisions: Class Cohesion Open-Closed Single Responsibility Interface Segregation Dependency Inversion Liskov Substitution.

Slides:



Advertisements
Similar presentations
Chapter 11 Component-Level Design
Advertisements

ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Issues.
General OO Concepts and Principles CSE301 University of Sunderland Harry R. Erwin, PhD.
Lecture 9 Improving Software Design CSC301-Winter 2011 – University of Toronto – Department of Computer Science Hesam C. Esfahani
CSE 425: Semantics II Implementing Scopes A symbol table is in essence a dictionary –I.e., every name appears in it, with the info known about it –Usually.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
Iterators T.J. Niglio Computer & Systems Engineering Fall 2003 Software Design & Documentation Object Behavioral.
Object-Oriented Metrics
Introduction to Inheritance Fall 2005 OOPD John Anthony.
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 1.
Developed by Reneta Barneva, SUNY Fredonia Component Level Design.
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
CSE 425: Object-Oriented Programming II Implementation of OO Languages Efficient use of instructions and program storage –E.g., a C++ object is stored.
CLASS DESIGN PRINCIPLES Lecture 2. The quality of the architecture What is a good design? It is the design that at least does not have signs of “bad”.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
1 OO Design Novosoft, 2001 by V. Mukhortov. 2 OO Design Goals  Flexibility Changes must be localized  Maintainability Modules requiring changes can.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Ch:10 Component Level Design Unit 4. What is Component? A component is a modular building block for computer software Because components reside within.
CSE 331 SOFTWARE DESIGN & IMPLEMENTATION MIDTERM REVIEW Autumn 2011.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
CSE 301 Exam Revision Lecture
Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution.
CSSE 374: More GRASP’ing for Object Responsibilities
Class Design III: Advanced Inheritance Additional References “Object-Oriented Software Development Using Java”, Xiaoping Jia, Addison Wesley, 2002 “Core.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-5 Software Engineering Design Goals.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
OO as a language for acm l OO phrase l Mental model of key concepts.
The Strategy Pattern SE-2811 Dr. Mark L. Hornick 1 Class 1-2.
Software Design Principles
Object Oriented Software Development
Incremental Design Why incremental design? Goal of incremental design Tools for incremental design  UML diagrams  Design principles  Design patterns.
Elements of OO Abstraction Encapsulation Modularity Hierarchy: Inheritance & Aggregation 4 major/essential elements3 minor/helpful elements Typing Concurrency.
SE-2811 Software Component Design Week 1, Day 2 (and 1-3 and 2-1) SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick 1.
1 Software Engineering: A Practitioner’s Approach, 6/e Chapter 11a: Component-Level Design Software Engineering: A Practitioner’s Approach, 6/e Chapter.
The Strategy Pattern SE-2811 Dr. Mark L. Hornick 1.
Five design principles
Inheritance Initialization & Destruction of Derived Objects Protected Members Non-public Inheritance Virtual Function Implementation Virtual Destructors.
Evaluating an Object-Oriented Design ©SoftMoore ConsultingSlide 1.
CHAPTER 3 MODELING COMPONENT-LEVEL DESIGN.
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
Component Design Elaborating the Design Model. Component Design Translation of the architectural design into a detailed (class-based or module- based)
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
Overview of C++ Polymorphism
Rohini Sharma Roll No. RA1809A01 Regd. No M.Tech.(CSE) Part Time 3 rd Semester.
Object-Oriented Programming “The Rest of the Story”, CS 4450 – Chapter 16.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 5th Edition Copyright © 2015 John Wiley & Sons, Inc. All rights.
Beginning Software Craftsmanship Brendan Enrick Steve Smith
14 Jul 2005CSE403, Summer'05, Lecture 09 Lecture 09: Fundamental Principles and Best Practices for Software Design Valentin Razmov.
Motivation for Generic Programming in C++
Sections Inheritance and Abstract Classes
Software Architecture & Difference from Design
CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2004.
Copyright © by Curt Hill
Software Engineering: A Practitioner’s Approach, 6/e Chapter 11 Component-Level Design copyright © 1996, 2001, 2005 R.S. Pressman & Associates, Inc.
Object-Oriented Metrics
TIM 58 Chapter 8: Class and Method Design
Design Metrics Software Engineering Fall 2003
Design Metrics Software Engineering Fall 2003
Component-Level Design
Overview of C++ Polymorphism
A (partial) blueprint for dealing with change
Some principles for object oriented design
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
Presentation transcript:

Object-oriented metrics Design decisions: Class Cohesion Open-Closed Single Responsibility Interface Segregation Dependency Inversion Liskov Substitution Law of Demeter Reused Abstractions

Class cohesion Class design should reduce the need to edit multiple classes when making changes to application logic. A fundamental goal of OO design is to place the –behaviour (methods) as close to the –data they operate on (attributes) as possible, so that changes are less likely to propagate across multiple classes

Class cohesion metrics Lack of Cohesion of Methods (LCoM) M #methods A attribute accessed by R(A) methods: LCoM = ((∑ R(A)-A) – M ) / (1- M)

Open-closed Once a class is tested and working, modifying its code can introduce new bugs. We avoid this by extending the class, leaving its code unchanged, to add new behaviour. Classes should be open to extension, but closed to modification

Open-closed metric Per successful check-in –classes extended and not modified / classes extended and/or modified

Single responsibility Changing code in a tested class can introduce new bugs. We seek to minimise the reasons why a class might need to change. The more different things a class does, the more reasons it might have to change.

Single responsibility metric Responsibility / class Responsibility := ?

Interface segregation If different clients depend on different methods of the same class, then a change to one method might require a recompile and redeployment of other clients who use different methods. Creating several client-specific interfaces, one for each type of client, with the methods that type of client requires, reduces this problem significantly.

Interface segregation If type T exposes N methods, and client C uses n of them, then T’s interface is n/N specific with respect to C. Average n/N for all clients of T

Dependency inversion Much of the duplication in code comes from client objects knowing about all sorts of specialised suppliers, that from the client’s perspective do similar things but in different ways. Polymorphism is a powerful mechanism that underpins OO design. It allows us to bind to an abstraction, and then we don’t need to know what concrete classes we are collaborating with. This makes it much easier to plug in new components with no need to change the client code.

Dependency inversion dependencies on abstractions / total dependencies

Liskov substitution principle Dynamic polymorphism is a pow erful mechanism that allows us to invert dependencies, reducing duplication and making change much easier. All OO design principles depend upon polymorphism, but we must ensure that any type can be substituted for any of its subtypes at run-time without having any adverse effect on the client. Subtypes must obey all of the rules that apply to their super-types, pre-conditions for calling methods, post- conditions of methods called, and invariants that always apply between method calls.

Frequently used OO metrics McCabe Efferent coupling Lack of Cohesion of Methods –Chidamber – Kemerer –Henderson-Sellers LOC # of attributes Inheritence level Nesting level

(weighted) McCabe Problem Without being given any additional information, how many execution paths could there be in the following code? String EvaluateSalaryAndReturnName( Employee e ) { if( e.Title() == "CEO" || e.Salary() > ) { cout << e.First() << " " << e.Last() << " is overpaid" << endl; } return e.First() + " " + e.Last(); } Answer: 23 (in just four lines of code!)

For the non-exceptional execution paths, the trick was to know C/C++'s short-circuit evaluation rule: 1. If e.Title() == "CEO" then the second part of the condition doesn't need to be be evaluated (e.g., e.Salary() will never get called), but the cout will be performed.[2] 2. If e.Title() != "CEO" but e.Salary() > , both parts of the condition will be evaluated and the cout will be performed. 3. If e.Title() != "CEO" and e.Salary() <= , the cout will not be performed. This leaves the exceptional execution paths: String EvaluateSalaryAndReturnName( Employee e ) ^*^ ^4^ 4. The argument is passed by value, which invokes the Employee copy constructor. This copy operation might throw. *. String's copy constructor might throw while copying the temporary return value into the caller's area. We'll ignore this one, however, since it happens outside this function (and it turns out that we have enough execution paths of our own to keep us busy anyway!). if( e.Title() == "CEO" || e.Salary() > ) ^5^ ^7^ ^6^ ^11^ ^8^ ^10^ ^9^

5. The Title() member function might itself throw, or it might return an object of class type by value, and that copy operation might throw. 6. To match a valid operator==, the string literal may need to be converted to a temporary object of class type (probably the same as e.Title()'s return type), and that construction of the temporary might throw. 7. If operator== is a programmer-supplied function, it might throw. 8. Similarly to #5, Salary() might itself throw, or it might return a temporary object and this construction operation might throw. 9. Similarly to #6, a temporary object may need to be constructed and this construction might throw. 10. Similarly to #7, this might be a programmer-provided function and therefore might throw. 11. Similarly to #7 and #10, this might be a programmer-provided function and therefore might throw (see note [2] again). cout << e.First() << " " << e.Last() << " is overpaid" << endl; As documented in the draft standard, any of the five calls to operator<< might throw Similarly to #5, First() and/or Last() might throw, or each might return a temporary object and those construction operations might throw. return e.First() + " " + e.Last(); Similarly to #5, First() and/or Last() might throw, or each might return a temporary object and those construction operations might throw. 21. Similarly to #6, a temporary object may need to be constructed and this construction might throw Similarly to #7, this might be a programmer-provided function and therefore might throw.