Lecture 13: Object- Oriented Concepts Anita S. Malik Adapted from Schach (2004) Chapter 7.

Slides:



Advertisements
Similar presentations
Introduction to Object Orientation System Analysis and Design
Advertisements

Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
1 OBJECT-ORIENTED CONCEPTS. 2 What is an object?  An object is a software entity that mirrors the real world in some way.  A software object in OOP.
Solutions to Review Questions. 4.1 Define object, class and instance. The UML Glossary gives these definitions: Object: an instance of a class. Class:
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Object-Oriented Analysis and Design
UHD::CS3320::CHAP61 INTRODUCTION TO OBJECTS Chapter 6.
2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
Chapter Object-Oriented Practices. Agenda Object-Oriented Concepts Terminology Object-Oriented Modeling Tips Object-Oriented Data Models and DBMSs.
1 From Modules to Objects Xiaojun Qi. 2 What Is a Module? A lexically contiguous sequence of program statements, bounded by boundary elements, with an.
1 SWE Introduction to Software Engineering Lecture 23 – Architectural Design (Chapter 13)
Slide 1 Systems Analysis & Design CS183 Spring Semester 2008 Dr. Jonathan Y. Clark Course Website:
Slide 7.1 © The McGraw-Hill Companies, 2002 Object-Oriented and Classical Software Engineering Fifth Edition, WCB/McGraw-Hill, 2002 Stephen R. Schach
Object-Oriented Databases
Object-oriented Programming Concepts
2-1 © Prentice Hall, 2004 Chapter 2: Introduction to Object Orientation (Adapted) Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra,
Object-oriented design CS 345 September 20,2002. Unavoidable Complexity Many software systems are very complex: –Many developers –Ongoing lifespan –Large.
C++ fundamentals.
Distribution of Marks Internal Sessional Evaluation Assignments – 10 Quizzes – 10 Class Participation Attendence – 5 Mid – Term Test – 25 External Evaluation.
Introduction To System Analysis and design
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Programming Languages and Paradigms Object-Oriented Programming.
Chapter 24 Introduction to Object DBMSs Prepared by Kai Huang CS157B Prof Sin-Min Lee.
Introduction to Object-oriented programming and software development Lecture 1.
BCS 2143 Introduction to Object Oriented and Software Development.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
An Object-Oriented Approach to Programming Logic and Design
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
1 CS 456 Software Engineering. 2 Contents 3 Chapter 1: Introduction.
Slide 7.1 Copyright © 2011 by The McGraw-Hill Companies, Inc. All rights reserved. Object-Oriented and Classical Software Engineering Eighth Edition, WCB/McGraw-Hill,
CS 403 – Programming Languages Class 25 November 28, 2000.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Slide 7.1 © The McGraw-Hill Companies, 2007 Object-Oriented and Classical Software Engineering Seventh Edition, WCB/McGraw-Hill, 2007 Stephen R. Schach.
Slide 20.1 Copyright © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. An Introduction to Object-Oriented Systems Analysis and Design with.
Chapter 12 Support for Object oriented Programming.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
7.1/108 Introduction To Objects 7.2/108 Modules Cohesion and low Coupling Data encapsulation Abstract data types Information hiding Objects Objects with.
ITEC 3220A Using and Designing Database Systems Instructor: Prof Z. Yang Course Website: 3220a.htm
Design Model Lecture p6 T120B pavasario sem.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
Learners Support Publications Object Oriented Programming.
Abstraction ADTs, Information Hiding and Encapsulation.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Software Engineering Zhang Shuang
Chapter 12 Object-oriented design for more than one class.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 7: Object-Oriented Design.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
Ch 7: From Modules to Objects (Part Two) CSCI 4320.
Slide 7B.31 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach.
© 2004 Pearson Addison-Wesley. All rights reserved January 23, 2006 Creating Objects & String Class ComS 207: Programming I (in Java) Iowa State University,
ISBN Chapter 12 Support for Object-Oriented Programming.
Object Oriented Programming in Java Habib Rostami Lecture 2.
Slide 7.1 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Object-Oriented Software Engineering WCB/McGraw-Hill, 2008 Stephen R.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Object-Oriented Programming
Sachin Malhotra Saurabh Choudhary
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
Creating Objects & String Class
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Types of Programming Languages
Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach
FROM MODULES TO OBJECTS.
Object-Oriented and Classical Software Engineering Eighth Edition, WCB/McGraw-Hill, 2011 Stephen R. Schach.
ITEC 3220A Using and Designing Database Systems
Workshop for Programming And Systems Management Teachers
Object-Oriented PHP (1)
Presentation transcript:

Lecture 13: Object- Oriented Concepts Anita S. Malik Adapted from Schach (2004) Chapter 7

CS540 Software Design 2Lecture 13 Object-Oriented Programming Objects can be used effectively to represent real- world entities Objects can be used effectively to represent real- world entities For instance, an object might represent a particular employee in a company For instance, an object might represent a particular employee in a company Each employee object handles the processing and data management related to that employee Each employee object handles the processing and data management related to that employee

3 Objects An object has: An object has: state - descriptive characteristics state - descriptive characteristics behaviors - what it can do (or what can be done to it) behaviors - what it can do (or what can be done to it) The state of a bank account includes its account number and its current balance The state of a bank account includes its account number and its current balance The behaviors associated with a bank account include the ability to make deposits and withdrawals The behaviors associated with a bank account include the ability to make deposits and withdrawals Note that the behavior of an object might change its state Note that the behavior of an object might change its state

CS540 Software Design 4Lecture 13 Classes An object is defined by a class An object is defined by a class A class is the blueprint of an object A class is the blueprint of an object Multiple objects can be created from the same class Multiple objects can be created from the same class

CS540 Software Design 5Lecture 13 Objects and Classes Bank Account A class (the concept) John’s Bank Account Balance: $5,257 An object (the realization) Bill’s Bank Account Balance: $1,245,069 Mary’s Bank Account Balance: $16,833 Multiple objects from the same class

CS540 Software Design 6Lecture 13 Attributes Contain current state of an object. Attributes can be classified as simple or complex. Attributes can be classified as simple or complex. Simple attribute can be a primitive type such as integer, string, etc., which takes on literal values. Simple attribute can be a primitive type such as integer, string, etc., which takes on literal values. Complex attribute can contain collections and/or references. Complex attribute can contain collections and/or references. Reference attribute represents relationship. Reference attribute represents relationship. complex object: contains one or more complex attributes complex object: contains one or more complex attributes

CS540 Software Design 7Lecture 13 Methods and messages Method: Defines behavior of an object, as a set of encapsulated functions. Message: Request from one object to another asking second object to execute one of its methods. (a) (b) (a) Object showing attributes and methods (b) Example of a method

CS540 Software Design 8Lecture 13 Classes Class: Blueprint for defining a set of similar objects. Objects in a class are called instances.

CS540 Software Design 9Lecture 13 Inheritance One class can be used to derive another via inheritance One class can be used to derive another via inheritance Classes can be organized into hierarchies Classes can be organized into hierarchies Bank Account Account Charge Account Savings Account Checking Account

CS540 Software Design 10Lecture 13 Inheritance (contd) Inheritance allows one class of objects to be defined as a special case of a more general class. Special cases are subclasses and more general cases are superclasses. Generalization: process of forming a superclass Specialization: forming a subclass Subclass inherits all properties of its superclass and can define its own unique properties. Subclass can redefine inherited methods. All instances of subclass are instances of superclass. Principle of substitutability: instance of subclass can be used whenever method/construct expects instance of superclass. A KIND OF (AKO): Name for relationship between subclass and superclass

CS540 Software Design 11Lecture 13 Types of inheritance (a) (b) (c) (a) Single (b) Multiple (c) Repeated (b)

CS540 Software Design 12Lecture 13 Inheritance (contd) Define humanBeing to be a class Define humanBeing to be a class A humanBeing has attributes, such as age, height, gender A humanBeing has attributes, such as age, height, gender Assign values to attributes when describing object Assign values to attributes when describing object Define Parent to be a subclass of HumanBeing Define Parent to be a subclass of HumanBeing A Parent has all attributes of a HumanBeing, plus attributes of his/her own (name of oldest child, number of children) A Parent has all attributes of a HumanBeing, plus attributes of his/her own (name of oldest child, number of children) A Parent inherits all attributes of humanBeing A Parent inherits all attributes of humanBeing The property of inheritance is an essential feature of object-oriented languages such as Smalltalk, C++, Ada 95, Java (but not C, FORTRAN) The property of inheritance is an essential feature of object-oriented languages such as Smalltalk, C++, Ada 95, Java (but not C, FORTRAN)

CS540 Software Design 13Lecture 13 Inheritance (contd) UML notation UML notation Inheritance is represented by a large open triangle Inheritance is represented by a large open triangle

CS540 Software Design 14Lecture 13 Java implementation

CS540 Software Design 15Lecture 13 Overriding and Overloading Overriding: Process of redefining a property within a subclass. Overloading: Allows name of a method to be reused with a class or across classes. Overriding Example: Might define method in Staff class to increment salary based on commission method void giveCommission(float branchProfit) { salary = salary * branchProfit; } May wish to perform different calculation for commission in Manager subclass: method void giveCommission(float branchProfit) { salary = salary * branchProfit; }

CS540 Software Design 16Lecture 13 Aggregation UML Notation UML Notation

CS540 Software Design 17Lecture 13 Association UML Notation UML Notation

CS540 Software Design 18Lecture 13 Equivalence of Data and Action Classical paradigm Classical paradigm record_1.field_2 record_1.field_2 Object-oriented paradigm Object-oriented paradigm thisObject.attributeB thisObject.attributeB thisObject.methodC() thisObject.methodC()

CS540 Software Design 19Lecture 13 Example – Chapter 7 Schach (2002) Design of an operating system for a large mainframe computer. It has been decided that batch jobs submitted to the computer will be classified as high priority, medium priority, or low priority. There must be three queues for incoming batch jobs, one for each job type. When a job is submitted by a user, the job is added to the appropriate queue, and when the operating system decides that a job is ready to be run, it is removed from its queue and memory is allocated to it Design of an operating system for a large mainframe computer. It has been decided that batch jobs submitted to the computer will be classified as high priority, medium priority, or low priority. There must be three queues for incoming batch jobs, one for each job type. When a job is submitted by a user, the job is added to the appropriate queue, and when the operating system decides that a job is ready to be run, it is removed from its queue and memory is allocated to it Design 1 (Next slide) Design 1 (Next slide) Low cohesion—operations on job queues are spread all over product Low cohesion—operations on job queues are spread all over product

CS540 Software Design 20Lecture 13 Data Encapsulation — Design 1

CS540 Software Design 21Lecture 13 Data Encapsulation — Design 2

CS540 Software Design 22Lecture 13 Data Encapsulation m_encapsulation has informational cohesion m_encapsulation has informational cohesion m_encapsulation is an implementation of data encapsulation m_encapsulation is an implementation of data encapsulation Data structure ( job_queue ) together with operations performed on that data structure Data structure ( job_queue ) together with operations performed on that data structure Advantages Advantages Development Development Maintenance Maintenance

CS540 Software Design 23Lecture 13 Data Encapsulation and Development Data encapsulation is an example of abstraction Data encapsulation is an example of abstraction Job queue example Job queue example Data structure Data structure job_queue job_queue Three new functions Three new functions i nitialize_job_queue i nitialize_job_queue add_job_to_queue add_job_to_queue delete_job_from_queue delete_job_from_queue Abstraction Abstraction Conceptualize problem at higher level Conceptualize problem at higher level job queues and operations on job queues job queues and operations on job queues not lower level not lower level records or arrays records or arrays

CS540 Software Design 24Lecture 13 Stepwise Refinement Step 1: Design in terms of high level concepts It is irrelevant how job queues are implemented Step 2: Design low level components Totally ignore what use will be made of them In 1st step, assume existence of lower level In 1st step, assume existence of lower level Concern is the behavior of the data structure Concern is the behavior of the data structure job_queue job_queue In 2nd step, ignore existence of high level In 2nd step, ignore existence of high level Concern is the implementation of that behavior Concern is the implementation of that behavior In a larger product, there will be many levels of abstraction In a larger product, there will be many levels of abstraction

CS540 Software Design 25Lecture 13 Data Encapsulation and Maintenance Identify aspects of product likely to change Identify aspects of product likely to change Design product so as to minimize the effects of change Design product so as to minimize the effects of change Data structures are unlikely to change Data structures are unlikely to change Implementation may change Implementation may change Data encapsulation provides a way to cope with change Data encapsulation provides a way to cope with change

CS540 Software Design 26Lecture 13 Implementation of Class JobQueue C++ Jav a Jav a

CS540 Software Design 27Lecture 13 Implementation of queueHandler C++ Java

CS540 Software Design 28Lecture 13 Data Encapsulation and Maintenance (contd) What happens if queue is now implemented as a two-way linked list of JobRecord? What happens if queue is now implemented as a two-way linked list of JobRecord? Module that uses JobRecord need not be changed at all, merely recompiled Module that uses JobRecord need not be changed at all, merely recompiled C++ C++ Java Java

CS540 Software Design 29Lecture 13 Abstract Data Types Problem with both implementations Problem with both implementations Only one queue Only one queue Need Need We need: We need: Data type + operations performed on instantiations of that data type Abstract data type Abstract data type

CS540 Software Design 30Lecture 13 Abstract Data Type (contd) (Problems caused by public attributes solved later) (Problems caused by public attributes solved later)

CS540 Software Design 31Lecture 13 Information Hiding Data abstraction Data abstraction Designer thinks at level of an ADT Designer thinks at level of an ADT Procedural abstraction Procedural abstraction Define a procedure—extend the language Define a procedure—extend the language Instances of a more general design concept, information hiding Instances of a more general design concept, information hiding Design the modules in way that items likely to change are hidden Design the modules in way that items likely to change are hidden Future change is localized Future change is localized Changes cannot affect other modules Changes cannot affect other modules

CS540 Software Design 32Lecture 13 Information Hiding (contd) C++ abstract data type implementation with information hiding C++ abstract data type implementation with information hiding

CS540 Software Design 33Lecture 13 Information Hiding (contd) Effect of information hiding via private attributes Effect of information hiding via private attributes

CS540 Software Design 34Lecture 13 Polymorphism and Dynamic Binding Classical paradigm Classical paradigm Must explicitly invoke correct version Must explicitly invoke correct version

CS540 Software Design 35Lecture 13 Polymorphism and Dynamic Binding (contd) Object-oriented paradigm Object-oriented paradigm

CS540 Software Design 36Lecture 13 Polymorphism and Dynamic Binding (contd) All that is needed is myFile.open() All that is needed is myFile.open() Correct method invoked at run-time (dynamically) Correct method invoked at run-time (dynamically) Method open can be applied to objects of different classes Method open can be applied to objects of different classes Polymorphic Polymorphic

CS540 Software Design 37Lecture 13 Polymorphism and dynamic binding (contd) Method checkOrder (b : Base) can be applied to objects of any subclass of Base Method checkOrder (b : Base) can be applied to objects of any subclass of Base

CS540 Software Design 38Lecture 13 Polymorphism and Dynamic Binding (contd) Can have a negative impact on maintenance Can have a negative impact on maintenance Code is hard to understand if there are multiple possibilities for a specific method Code is hard to understand if there are multiple possibilities for a specific method Polymorphism and dynamic binding Polymorphism and dynamic binding Strength and weakness of the object-oriented paradigm Strength and weakness of the object-oriented paradigm

CS540 Software Design 39Lecture 13 Polymorphism and dynamic binding (contd) Polymorphism: Means ‘many forms’. Dynamic Binding: Runtime process of selecting appropriate method based on an object’s type. Example: With list consisting of an arbitrary no. of objects from the Staff hierarchy, we can write:list[i]. print and runtime system will determine which print() method to invoke depending on the object’s (sub)type.

CS540 Software Design 40Lecture 13 Cohesion and Coupling of Objects No such thing! No such thing! Object-oriented cohesion and coupling always reduces to classical cohesion Object-oriented cohesion and coupling always reduces to classical cohesion The only feature unique to the object-oriented paradigm is inheritance The only feature unique to the object-oriented paradigm is inheritance Cohesion has nothing to do with inheritance Cohesion has nothing to do with inheritance Two objects with the same functionality have the same cohesion Two objects with the same functionality have the same cohesion It does not matter if this functionality is inherited or not It does not matter if this functionality is inherited or not Similarly, so-called object-oriented coupling always reduces to classical coupling Similarly, so-called object-oriented coupling always reduces to classical coupling

CS540 Software Design 41Lecture 13 Object-Oriented Metrics (contd) Two types of so-called object-oriented metric Two types of so-called object-oriented metric Not related to inheritance Not related to inheritance Reduces to a classical metric Reduces to a classical metric Inheritance-related Inheritance-related May reduce to a classical metric May reduce to a classical metric No problem No problem Classical metrics work just fine Classical metrics work just fine But don’t mislead others by calling them object- oriented But don’t mislead others by calling them object- oriented

CS540 Software Design 42Lecture 13 Advantages of Objects Same as as advantages of abstract data types Same as as advantages of abstract data types Information hiding Information hiding Data abstraction Data abstraction Procedural abstraction Procedural abstraction Inheritance provides further data abstraction Inheritance provides further data abstraction Easier and less error-prone product development Easier and less error-prone product development Easier maintenance Easier maintenance Objects are more reusable than modules with functional cohesion Objects are more reusable than modules with functional cohesion

CS540 Software Design 43Lecture 13 Summary