Criteria for good design. aim to appreciate the proper and improper uses of inheritance and appreciate the concepts of coupling and cohesion.

Slides:



Advertisements
Similar presentations
Chapter 11 Component-Level Design
Advertisements

General OO Concepts and Principles CSE301 University of Sunderland Harry R. Erwin, PhD.
Solutions to Review Questions. 4.1 Define object, class and instance. The UML Glossary gives these definitions: Object: an instance of a class. Class:
Inheritance Inheritance Reserved word protected Reserved word super
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
ITEC200 – Week03 Inheritance and Class Hierarchies.
1 Software Testing and Quality Assurance Lecture 12 - The Testing Perspective (Chapter 2, A Practical Guide to Testing Object-Oriented Software)
1 CS1001 Lecture Overview Homework 3 Homework 3 Project/Paper Project/Paper Object Oriented Design Object Oriented Design.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
03/12/2001 © Bennett, McRobb and Farmer Class Design Based on Chapter 14 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design.
Liskov Substitution Principle
Advanced Object-Oriented Programming Features
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Criteria for good design. aim to appreciate the proper and improper uses of inheritance and appreciate the concepts of coupling and cohesion.
Object-oriented Programming Concepts
Chapter 10 Class and Method Design
7M822 UML Class Diagrams advanced concepts 15 September 2008.
Developed by Reneta Barneva, SUNY Fredonia Component Level Design.
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Systems Design. Analysis involves understanding and documenting user requirements in a clear and unambiguous way. It focuses on the business side and.
Slide 1 Chapter 10 Class and Method Design. Slide 2 REVISITING THE BASIC CHARACTERISTICS OF OBJECT-ORIENTATION.
3/15/05H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
OO Analysis and Design CMPS OOA/OOD Cursory explanation of OOP emphasizes ▫ Syntax  classes, inheritance, message passing, virtual, static Most.
Inheritance using Java
Systems Analysis and Design in a Changing World, Fifth Edition
BCS 2143 Introduction to Object Oriented and Software Development.
Objects and Components. The adaptive organization The competitive environment of businesses continuously changing, and the pace of that change is increasing.
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
Database Management System Prepared by Dr. Ahmed El-Ragal Reviewed & Presented By Mr. Mahmoud Rafeek Alfarra College Of Science & Technology Khan younis.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
© 2005 Prentice Hall9-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
CS212: Object Oriented Analysis and Design Lecture 13: Relationship between Classes.
OO as a language for acm l OO phrase l Mental model of key concepts.
Object Oriented Software Development
Relationships Relationships between objects and between classes.
CSC 131 Fall 2006 Lecture # 6 Object-Oriented Concepts.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
1 Software Engineering: A Practitioner’s Approach, 6/e Chapter 11a: Component-Level Design Software Engineering: A Practitioner’s Approach, 6/e Chapter.
Coming up: Inheritance
Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance  Problems with implementation inheritance: Encapsulation Fragile Base Class.
CHAPTER 3 MODELING COMPONENT-LEVEL DESIGN.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Component Design Elaborating the Design Model. Component Design Translation of the architectural design into a detailed (class-based or module- based)
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 5th Edition Copyright © 2015 John Wiley & Sons, Inc. All rights.
COP 4331 – OOD&P Lecture 7 Object Concepts. What is an Object Programming language definition: An instance of a class Design perspective is different.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Basic Characteristics of Object-Oriented Systems
3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
Software Construction Lab 05 Abstraction, Inheritance, and Polymorphism in Java.
Object Oriented Programming in Java Habib Rostami Lecture 2.
11 Systems Analysis and Design in a Changing World, Fifth Edition.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Sections Inheritance and Abstract Classes
CS212: Object Oriented Analysis and Design
Object-Oriented Modeling
Chapter 11 Object-Oriented Design
Types of Programming Languages
TIM 58 Chapter 8: Class and Method Design
Component-Level Design
Object-Oriented Design
Chapter 20 Object-Oriented Analysis and Design
Object Oriented Analysis and Design
Presentation transcript:

Criteria for good design

aim to appreciate the proper and improper uses of inheritance and appreciate the concepts of coupling and cohesion

Advanced Generalisation and Inheritance Modelling Generalisation (specialisation) and inheritance are not the same – generalisation is a semantic relationship between classes – the interface of the subclass must include all properties of the superclass Inheritance – the mechanism by which more specific elements incorporate structure and behaviour defined by more general elements Generalisation is a useful and powerful concept but can also create many problems due to the intricate mechanisms of inheritance

Generalisation and Substitutability Generalisation introduces additional classes and categorises them into generic and more specific classes – establishes superclass-subclass relationships into the model The benefits of generalisation arise from the substitutability principle – a subclass object can be used in place of a superclass object in any part of the code where the superclass object is accessed – this means it can reduce the overall number of association and aggregation relationships in the model – unfortunately, inheritance may be used in a way that defeats the benefits of the substitutability principle

The Substitution Principle Defined by Barbara Liskov, so known as the Liskov Substitution Principle (LSP) – it should be possible to treat a derived object as if it were a base object

Inheritance v. Encapsulation Encapsulation – an object's state should only be accessible via the operations in the object's interface Inheritance may compromise encapsulation – subclasses may be allowed to access protected attributes directly – objects belonging to different classes may be friends of each other or have elements with package visibility Applications should be designed so that they balance the desired level of encapsulation against inheritance

Interface Inheritance v. Implementation Inheritance Interface inheritance – when generalisation is used with the aim of substitutability, it can be realised using interface inheritance (subtyping, or type inheritance)  this is both a “harmless” as well as a very desirable form of inheritance  a subclass inherits attribute types and operation signatures  the implementation of inherited operations may be deferred – there is a difference between an interface class and an abstract class  interface classes defer the definition of operations – these are defined or implemented by another class  abstract classes can provide a partial implementation of some operations

Interface Inheritance v. Implementation Inheritance Implementation inheritance – when generalisation is used to imply code reuse it is realised using implementation inheritance – implementation inheritance combines the superclass properties in the subclasses and allows them to be overridden with new implementations when necessary -- overriding can mean the inclusion (or call) of a superclass method in the subclass method -- overriding can also mean a complete replacement of the superclass method by the subclass method Implementation inheritance can be harmful if it is not carefully controlled

Extension Inheritance The only proper use of inheritance is as an incremental definition of a class – a subclass has more properties than its superclass – a subclass is a kind of superclass This type of inheritance is known as extension inheritance In extension inheritance, the overriding of properties should be used with care – it should be used to make properties more specific, and not to change the meaning of the property

Extension Inheritance

Restriction Inheritance It is possible to use inheritance as a restriction mechanism whereby some of the inherited properties are suppressed or overridden in the subclass – this type of inheritance is known as restriction inheritance Restriction inheritance is problematic – a subclass does not include all the properties of the superclass but a superclass object can still be substituted by a subclass object -- whoever is using the object should be aware of the overridden properties Restriction inheritance may give rise to maintenance problems

Restriction Inheritence

Convenience Inheritance

The Evils of Implementation Inheritance

Aggregation as an Alternative to Generalisation

Delegation

Generalisation V Aggregation

Coupling and Cohesion

Example of Poor Coupling

Example of Poor Cohesion

Criteria for Good Design - Coupling Coupling – a good design will minimise coupling – describes the degree of interconnectedness between design components – is reflected by the number of links an object has and by the degree of interaction the object has with other objects Interaction coupling – a measure of the number of message types an objects sends and the number of parameters passed with these message types Inheritance coupling – the degree to which a subclass needs the features it inherits from its base class

Inheritance Coupling - example

Criteria for Good Design - Cohesion

Class Cohesion - example

Specialisation Cohesion - example

Summary