1 COSC3306: Programming Paradigms Lecture 6: Object-Oriented Programming Specifications Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003.

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Classes & Objects Computer Science I Last updated 9/30/10.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Object-Oriented Databases v OO systems associated with – graphical user interface (GUI) – powerful modeling techniques – advanced data management capabilities.
1 SWE Introduction to Software Engineering Lecture 23 – Architectural Design (Chapter 13)
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Object-Oriented Databases
Object-oriented Programming Concepts
Copyright 2004 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Second Edition Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Appendix.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
Chapter 13: Object-Oriented Programming
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
Object Oriented Databases - Overview
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
C++ fundamentals.
Object Oriented Software Development
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.
Introduction to Object-oriented programming and software development Lecture 1.
11 1 Object oriented DB (not in book) Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Learning objectives: What.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
An Object-Oriented Approach to Programming Logic and Design
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Copyright 2001 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Appendix A Object-Oriented.
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.
Unified Modeling Language, Version 2.0
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
Chapter 12 Support for Object oriented Programming.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
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.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Learners Support Publications Object Oriented Programming.
Abstraction ADTs, Information Hiding and Encapsulation.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Object-Oriented Programming Chapter Chapter
Slide 1 Systems Analysis and Design With UML 2.0 An Object-Oriented Approach, Second Edition Chapter 2: Introduction to Object-Oriented Systems Analysis.
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
ISBN Object-Oriented Programming Chapter Chapter
1 Unified Modeling Language, Version 2.0 Chapter 2.
CMSC 345 Fall 2000 OO Design. Characteristics of OOD Objects are abstractions of real-world or system entities and manage themselves Objects are independent.
OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall Appendix A Object-Oriented Analysis and Design A.1.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
ISBN Chapter 12 Support for Object-Oriented Programming.
Chapter 11: Abstract Data Types Lecture # 17. Chapter 11 Topics The Concept of Abstraction Advantages of Abstract Data Types Design Issues for Abstract.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
 The Object Oriented concepts was evolved for solving complex problems. Object- oriented software development started in the 1980s. Object-oriented design.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
JAVA By Waqas.
Object-Oriented Analysis and Design
Systems Analysis and Design With UML 2
OOP What is problem? Solution? OOP
About the Presentations
Object Oriented Concepts -I
Object Oriented Programming in Java
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Types of Programming Languages
Presentation transcript:

1 COSC3306: Programming Paradigms Lecture 6: Object-Oriented Programming Specifications Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003

2 Specification of OOPL The object-oriented programming allows one to construct programs the way we humans tend to think about things. For example, –We tend to classify real-world entities such as vehicles, airplanes, ATM machines, and so on. –Take a class of vehicles, all vehicles have certain components, such as engine, wheels, transmissions, and so on. –All vehicles exhibit some kind of behavior, such as acceleration, deceleration, and turning.

3 How object-oriented model can be represented? One way is that an object may include persistent data and several data types with their associated operations. © 2003 Brooks/Cole Publishing / Thomson Learning™ Figure 8.1 The Operation/Parameter model

4 Representation In the following, the message Perimeter can be sent to an object, which will behave according to its own method for handling the message. In this Figure, Square represents an active object with both of its data attributes, w and s, having values. Objects of type triangle or square each have two methods, namely Perimeter and Area.

5 Figure 8.2 The Message/Object model © 2003 Brooks/Cole Publishing / Thomson Learning™

6 Representation As a consequence of the above discussion, we can say that, the object- oriented approach provides a programming method that consists of objects sending messages to other objects.

7 Design Principles for OOP The object-oriented programming model has as its fundamental entity the object, which consists of a local state and a set of actions that it can perform, called methods. These methods are activated when the object receives an appropriate message, in which the actions consist of modification of the state of the object and the sending of messages to other objects. The local state structure of an object and the methods that it can perform are specified by the class, which defines the object. In this sense, an object is called an instance of its class. A class is used as a syntactic mechanism in almost all object-oriented languages, in which an individual representative of a class is known as an instance.

8 Objects A module that consists of a hidden variable together with a group of exported operations on that variable. One way to view an object is as a pair consisting of behavior and state. –The behavior of a component is the set of actions it can perform. The complete description of all the behaviors for a component is sometimes called the protocol, in which includes all activities involved. –The state of a component represents all the information held within it. It is worth noting that, the state is not static and can be changed over time (dynamic). –The state is described by the instance variables, whereas the behavior is characterized by the methods, in which provide the appropriate behavior through modifications of the state as well as by interacting with other objects.

9 Classes A class is a template for objects and contains of the following: –Descriptions of the actions an object can perform. –Definition of the structure of an object. In other words, a class must provide a means for defining the forms of objects. What data do they own? What can they do? How do they do things? A class is similar to an abstract data type which defines the type data structure and procedures that apply to it.

10 Messages It is often useful to think of computation in an object-oriented system as evolving around messages. A message is a request transferred from one object to another in order the receiving object to produce some desired result. Using this analogy, objects in the system manipulate other objects by sending messages requesting them to perform specific action.

11 Unary Messages Unary Messages have no parameters. They have only two parts, the object to which they are to be sent and the name of the method in that receiving object. In this respect, the first symbol of an unary message specifies a receiver object, and the second symbol specifies the method of that object that is to be executed. For example, the message SecondChild Boy sends a parameterless message to the Boy method of the object SecondChild. Recall that all objects are referenced by pointers, so SecondChild is really a pointer to an object.

12 Binary Messages Binary Messages have a single parameter, an object, which is passed to the specified method of the specified receiver object. Among the most common binary messages are those for arithmetic operations. For example, in the message 20  10 the receiver object is the number 20, to which is sent the message  10. In this respect, the message passes the parameter object 10 to the  method of the object 20. The code of that method uses the object 10 to build a new object, in this case 30. If the system already contains the object 30, then the result is a reference to it rather than to a new object.

13 Keyword Messages Keyword Messages specify one or more keywords to organize the correspondence between the actual parameters in the message and the formal parameters in the method. In other words, the keywords select the method to which the message is directed. Methods that accept keyword messages are not named, but instead are identified by the keywords themselves. For example, consider the following message FirstArrayHead: 1Tail: 5 which sends the objects 1 and 5 to a particular method, “Head :” and “Tail :”, of the object FirstArray. The keywords “Head :” and “Tail :” identify the formal parameters of the method to which 1 and 5, respectively, are to be sent. In this respect, the method to which this message is sent includes the keywords of the message.

14 Methods A method consists of the operations that an object performs when it receives a message. A one-to- one correspondence between messages and the methods that are executed when a given message is received by an object of a particular class. Objects of different classes might perform different methods for the same message if that message were bound to a different method in the definition of the two classes. In contrast, if a message corresponds to a procedure call, then the method corresponds to the procedure itself.

15 Example An object-oriented model consisting of different objects to accomplish some methods of communication. Communication from an object Student to the object Financial-Aid, as indicated by arrow, is through the messages ID and Transaction. The Financial-Aid can respond by sending messages Money and Receipt. The object Financial-Aid is thought of as an active entity including data and also capable of sending messages, receipts, or money whereas algorithms manipulate passive data.

16 Figure 8.3 Object-oriented representation of financial-aid-receiving problem © 2003 Brooks/Cole Publishing / Thomson Learning™

17 Implementing OOP In general, an object-based language supports: –Data Abstraction (Encapsulation of state with Operations) –Encapsulation (Information Hiding) –Polymorphism (Message Passing) and a language that is object-oriented also implements: –Inheritance, and –Dynamic Binding. In this context, inheritance is the ability to organize object classes into a hierarchy of subclasses and superclasses, and for operations of a given class to be applicable to objects of a subclass. The key concepts that are common to the implementation of each object- oriented programming language are as the following.

18 Data Abstraction One of the recent trends in programming methodology and programming languages has been the specification of Abstract Data Types (ADT). That is, the programmer first decides what data structures and data types are required and then specifies the necessary operations in terms of their inputs and outputs. Finally, the representation of the data structures and operations is fixed; addressing that the abstract data type is implemented. From the theoretical point of view, an abstract data type is defined as a collection of data structures and operations abstracted into a simple data type.

19 Definition of Abstraction A set of data objects, ordinarily using one or more type definitions. A set of abstract operations on those data objects. When we design an abstract data type, we should make sure that the constructors (e.g., int and push) and selectors (operations implemented) work together smoothly. This is necessary if the data type is to be easy to learn and easy to use.

20 Languages’ support The language directly supplies a useful set of abstractions that we think of as the features of the language. The language provides facilities that aid the programmer to construct abstractions. Subprograms, subprogram libraries, type definitions, classes and packages are some of the facilities provided by different languages to support programmer-defined abstractions.

21 Example Consider a list of the grocery items. In this respect, grocery list contains items of the same type: milk, eggs, butter, apples, bread, chicken, etc. What can you do to the items on a list? You might count the items to determine the length of the list, add an item to the list, remove an item from the list, or look at an item. The items on a list together with operations that you can perform on the items form an abstract data type.

22 Operations of ADT List Create an empty list. Determine whether a list is empty. Determine the number of items on a list. Add an item at a given position in the list. Remove the item at a given position in the list. Remove all the items from the list. Retrieve the item at a given position in the list.

23 Implement ADT The first reaction to the implementation might be to choose a data structure and then to write methods that operate on it in accordance with the operations. In a non-object-oriented implementation, both the data structure and the abstract data type operations are distinct pieces. In contrast, object-oriented implementation provides encapsulation as a fundamental principles of abstract data type implementation which is the main focus of the next section.

24 Encapsulation Encapsulation or information hiding is simply the idea of packaging things together in a well-defined programming unit. When information is encapsulated in an abstraction, it means that the user of the abstraction: –Does not need to know the hidden information in order to use the abstraction, and –Is not permitted to directly use or manipulate the hidden information even if desiring to do so. For example, –The integer data type in a programming language not only hides the details of the integer number representation, but also effectively encapsulates the representation so that the programmer cannot manipulate individual bits of the representation of an integer. –The class in C++ provides for encapsulation by packaging both data and function members into a single class unit.

25 Polymorphism One of the most powerful capabilities of inheritance in object-oriented programming languages is its support for polymorphism, the ability to have classes in the same inheritance hierarchy respond differently to the same message. One of the most powerful capabilities of inheritance in object-oriented programming languages is its support for polymorphism, the ability to have classes in the same inheritance hierarchy respond differently to the same message. Two categories: –Pure polymorphism occurs when a single function can be applied to arguments (objects) of a variety of types. In pure polymorphism, there is one function (code body) and a number of interpretations. –Ad hoc polymorphism sometimes called overloading occurs when there are a number of different functions (code bodies) all denoted by the same name. This is in direct contrast to pure polymorphism, in which functions that are part of the same class have different signatures.

26 Inheritance Inheritance is one of the most important properties of the object-oriented programming because of its support for reusability. This property applies to classes. For example, class A is said to inherit from class B if A is a subclass of B and B is a superclass of A. –The advantage of inheritance is that it permits the reuse of many of the features of a superclass without respecifying them. –The ability to modify or remove inherited features selectively makes inheritance much more powerful. Inheritance may be either –Single if each class has just one parent –Multiple when classes are permitted to have more than one parent.

27 Figure 8.4 An inheritance graph for graphical objects © 2003 Brooks/Cole Publishing / Thomson Learning™

28 Dynamic Binding When a programming language determines how a particular operation is to be performed on an object, it is said to bind a specific implementation of that operation to the object. In other words, the property of attaching a message to method when a message is sent is known as binding. If the system decides on which implementation of the operation to use at compile time, it performs static binding. This property is dynamic binding (sometimes called late binding) if it is carried out every time a message is forwarded, indicating that the choice is made at run time.

29 Desirable Characteristics for OOP Close correspondence to the problem domain, meaning that the objects in programs correspond directly to objects in the problem domain, and their activities correspond as well. Reusability of software, meaning that the inheritance of properties by one class of projects from another class without explicitly respecifying them. Abstraction and encapsulation, meaning that the object- oriented model carries with it all the abstraction benefits of abstract data types by permitting the data and actions of an object to be encapsulated within that object and dividing its contents between those that are public and those that are private. Collecting similar operations, meaning that similar operations from two different components are collected into a new component. Concurrency, meaning that objects can act concurrently in the problem domain.

30 Summary OOP = –Objects (Abstraction) –+Classes (ADT) –+Inheritances (Classification) –+Overloading (Polymorphism) –+Dynamic Binding (Polymorphism)