Object Oriented Analysis and Design Object-Oriented Concepts
OOAD Concepts Class Object Encapsulation Abstraction Inheritance Polymorphism Message passing Dynamic binding
Classes & Objects Data / attributes / field/state Method / Behaviour Describe the characteristics Method / Behaviour Perform operations Perform object to object communication
Classes & Objects Class Object Category or group of things that have the same attributes and the same behaviors. Class is a decryption of properties and behaviors which a collection of same type objects can have Object Instance of a class Object is a bundle of properties and behaviors An object stores its state in fields (variables) and exposes its behavior through methods (functions)
Classes & Objects Attribute/Field/variable Data/Value Student Nimal age 21 Study() Study() Class Object
Classes & Objects Class Object User defined data type Instance of user defined data type Prototype or model Containing features Do not occupy memory Occupy memory Cant manipulate since its not in memory Can manipulate
Classes & Objects class Student { private : int AM; int EM; public : void ReadMarks() cout<<"Enter Assignment Marks : "; cin>>AM; } void printGrade() cout<<"Grade :"<<(AM+AM)/2; }; main() { Student Nimal; Nimal.ReadMarks(); Nimal.printGrade(); getch(); }
Classes & Objects Member functions defined outside class Binary scope resolution operator (::) ties member name to class name scope resolution operator help uniquely identifying functions of a particular class Different classes can have member functions with same name
Classes & Objects class Student { private : int AM; int EM; public : void ReadMarks(); void printGrade(); }; void Student::ReadMarks() cout<<"Enter Assignment Marks : "; cin>>AM; cin>>AM; } void Student::printGrade() { cout<<"Grade :"<<(AM+AM)/2; } main() Student Nimal; Nimal.ReadMarks(); Nimal.printGrade(); getch();
Constructors Constructors are special member functions of any class, which are invoked at the moment an instances of the class are created. They are special functions that have the same name as their class. Have the same name as the class. It may take arguments. It cannot return a value [including void].
Constructors Default Constructor Parameterized Constructor Accepts no parameters Called if no user-defined constructors Parameterized Constructor A constructor that receives arguments/parameters Class:: Circle() {} Circle::Circle(int r) { radius = r;}
Destructors Special member function Having same name as class Preceded with tilde (~) No arguments No return value Cannot be overloaded Invoked before system reclaims object’s memory Used in reusing memory for new objects
Pointers Memory location which hold the address of another memory location/ variable int x=5; int *p; p= &x; *p=10;