130 likes | 154 Views
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 Describe the characteristics Method / Behaviour
E N D
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 • Describe the characteristics • Method / Behaviour • Perform operations • Perform object to object communication
Classes & Objects • Class • 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 Data/Value Attribute/Field/variable Student Nimal age 21 Study() Study() Class Object
Classes & Objects main() { Student Nimal; Nimal.ReadMarks(); Nimal.printGrade(); getch(); } class Student { private : int AM; int EM; public : void ReadMarks() { cout<<"Enter Assignment Marks : "; cin>>AM; cout<<"Enter Assignment Marks : "; cin>>AM; } void printGrade() { cout<<"Grade :"<<(AM+AM)/2; } };
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 void Student::printGrade() { cout<<"Grade :"<<(AM+AM)/2; } main() { Student Nimal; Nimal.ReadMarks(); Nimal.printGrade(); getch(); } class Student { private : int AM; int EM; public : void ReadMarks(); void printGrade(); }; void Student::ReadMarks() { cout<<"Enter Assignment Marks : "; cin>>AM; cout<<"Enter Assignment Marks : "; cin>>AM; }
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 • 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;