Download presentation
Presentation is loading. Please wait.
Published byJewel Price Modified over 8 years ago
1
MAITRAYEE MUKERJI Object Oriented Programming in C++
2
Issues in Procedural/ Structured Languages Procedural languages: Pascal, Fortran, and C Large programs are usually divided into modules and functions Issues Unrestricted access to global data Poor modeling of the real world
3
Issues in Procedural/ Structured Languages Unrestricted access and difficult to maintain data integrity Data normally does not have an owner Functions, the building blocks are usually defined global Many functions can work on the same data Data Function 1 Function 2 Function 3
4
Contd.
5
Issues in Procedural Languages Resource de-allocation does not take place automatically : memory, open files, open database and network connections – memory leaks etc. Insufficient support for abstractions / inadequate modeling of real world entity In procedural languages, data is separated from the functions that operate on the data
6
Stack & Queue Functions struct Stack {int top; char*data; } struct Queue {int front, rear; char*data } Insert() Pop (); Delete() Push(); Issues in Procedural Languages Global Functions
7
HORSE EAGLE struct Horse {int age; intweight; intcolor; } gallop() canter() struct Eagle {int age; intweight; intwingspan; } fly() hunt() Issues in Procedural Languages Eagle can gallop Horse can fly
8
Object An object can be defined as a tangible entity that exhibits some well-defined behavior (Booch et. al., 2007) Complex real-world objects have both attributes and behaviour
9
Object Attributes / Characteristics Attributes in the real world are equivalent to data in a program: they have a certain specific values Nouns Behaviour / Response to some stimulus Behaviour is like a function: one calls a function to do something (display the inventory, for example) and it does it. Verbs
10
Example Student Name, Roll No, DoB, Enrolled Prgm, Year of Enrollment AddName(), DeleteName(), UpdateName() Shape Number of Sides, No of Vertices, List of adjacent sides Draw(), Color(), Resize()
11
Objects - Examples Data Storage Constructs Customised arrays, stacks, linked lists, trees Human entities Employees, Students, Customers, Sale persons Collection of data Inventory, Dictionary, Personnel file Physical Objects: Automobiles in a traffic-flow simulation Electrical components in a circuit-design program Countries in an economic model Aircraft in an air traffic control system Elements of the computer-user environment Windows, Menus, Graphic Objects (lines, rectangle etc). Mouse, Keyboard, Printer
12
Object Oriented Approach Unifying concept in computer science Any problem is conceptualized in terms of objects Look at a programming problem in terms of objects instead of functions Classes and objects as building blocks instead of algorithms Better modeling of real world entities
13
Object Oriented Approach Procedural Approach Vs Object Oriented Approach Computing and Printing a Paycheck Sorting a list of names
14
Object Oriented Programming Object-oriented programming is a method of implementation in which programs are organized as cooperative collections of objects, each of which represents an instance of some class, and whose classes are all members of a hierarchy of classes united via inheritance relationships (Booch et. al. 2007).
15
Contd. There are three important parts to this definition: Object-oriented programming uses objects, not algorithms, as its fundamental logical building blocks Each object is an instance of some class; and Classes may be related to one another via inheritance relationships
16
Object Oriented Language A language is object-oriented if and only if it satisfies the following requirements: It supports objects that are data abstractions with an interface of named operations and a hidden local state. Objects have an associated type [class]. Types [classes] may inherit attributes from super types [superclasses]. ( Cardelli and Wegner, cited from Booch et. Al. 2007) Such languages support inheritance i.e. it is possible to express “is a” relationships among types
17
Object Oriented Language Combine into a single unit both data and the functions that operate on that data. Such a unit is called an object. An object’s functions, called member functions in C++, typically provide the only way to access its data. If you want to read a data item in an object, you call a member function in the object. It will access the data and return the value to you. You can’t access the data directly.
18
Contd. If you want to modify the data in an object, you know exactly what functions interact with it: the member functions in the object. No other functions can access the data. This simplifies writing, debugging, and maintaining the program. Data and its functions are said to be encapsulated into a single entity. Data encapsulation and data hiding are key terms in the description of object-oriented languages. The data is hidden, so it is safe from accidental alteration.
19
Example
20
Key Features of Object Oriented Language Four major elements: Abstraction Encapsulation Modularity Hierarchy Three minor elements: Typing Concurrency Persistence
21
Key Features … An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of objects and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer. Encapsulation is the process of compartmentalizing the elements of an abstraction that constitute its structure and behavior; encapsulation serves to separate the contractual interface of an abstraction and its implementation. Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules.
22
Key Features Hierarchy is a ranking or ordering of abstractions. Typing is the enforcement of the class of an object, such that objects of different types may not be interchanged or, at the most, may be interchanged only in very restricted ways. Concurrency is the property that distinguishes an active object from one that is not active. Persistence is the property of an object through which its existence transcends time and/or space.
23
C++ Object Oriented Features
24
Contd.
25
References Chapter 2 and Appendix A: Object Oriented Programming Language from Booch et. al. http://www.enel.ucalgary.ca/People/Smith/619.94/ prev689/61994.96/1996/talks/tbooch.htm http://www.enel.ucalgary.ca/People/Smith/619.94/ prev689/61994.96/1996/talks/tbooch.htm http://www.umsl.edu/~sauterv/analysis/488_f01_p apers/quillin.htm http://www.umsl.edu/~sauterv/analysis/488_f01_p apers/quillin.htm
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.