Download presentation
Presentation is loading. Please wait.
Published byEdward Newman Modified over 9 years ago
1
1 OOP - An Introduction ISQS 6337 John R. Durrett
2
Development Paradigms Increasing program complexity 1. Front panel switches 2. Assembly language 3. High level languages (3gl)(COBOL) 4. Structured Programming –reduce complex to simple parts –top down 5. OOP –self-contained == data + methods –inside out from classes
3
3 Top Down, procedure- oriented design steps Identify tasks (verbs) to perform Stepwise refinement (N. Wirth) –break task into sub-tasks until sub-tasks are simple enough to implement directly Write procedures to solve sub- tasks Combine simple procedures to create functionality required
4
4 Procedural Programming
5
5 OO design steps Identify objects (nouns) in environment Establish behavior and attributes in objects Identify relationships between objects Specify class/object interface & implementation
6
6 Object Oriented Programming
7
7 Classes & Objects Class –abstract pattern or template –“cookie cutter” –interface defining behavior –description of data & related operations Object –particular instance or specimen –“cookie” –instantiation of abstract class –definition of memory
8
8 Example: Integers Data (Attributes, fields, data members) –Integers Operations ( Methods, member funcs ) –Account_Balance() –Deposit() –Withdrawal() –Interest() All a user needs to care about is information input to operations and info returned
9
Encapsulation (information hiding) binds data & code together black box –no need for programmer to understand how methods are implemented fields are safe from outside interference –program never access data members –only access is through public methods –semi-global variables key is to make data private & provide public access methods –i.e. a well defined interface
10
10 C++ Access specifiers - control level of encapsulation All can contain data & methods public –available anywhere with scope –provide interface to private –like struct private –accessible only through public member methods protected –Just like private (for now) friend
11
Polymorphism one name many purposes – C: abs() labs() fabs() – C++ abs() one interface multiple methods function overloading operator overloading compile time polymorphism – int abs(int); – long abs(long); – float abs(float);
12
12 Methods Functions that are members of class & therefore available in objects interface to private data Constructors (next slide) Mutators Accessors Destructors
13
Initialization automatic initialization of member data Constructors C++ ex: class myclass { private:// default for class int a; public: myclass (int x); void show(); }; myclass::myclass(int x) { a = x; } void myclass::show(void) { cout << a; } void main(){ myclass ob(4); ob.show(); // ok ob.a = 12; // wrong! }
14
Inheritance one object acquires properties of another hierarchical classification single inheritance (Java) multiple inheritance (C++) class - abstract representation object - defined variable of class type
15
15 Operator Overloading Increased flexibility Increased ease of use Increased control of class actions Not in java Example Employee E1, E2; E1 = E2; cout << E1; Class-1.cpp example
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.