100 likes | 196 Views
Object orientation concepts. Building blocks of modern software practice. Classes and Objects. Physical entities User interface components Rules Controllers Protocols Schedulers. Classes. Similar objects constitute a class ADTs (Abstract Data Types) Data
E N D
Object orientation concepts Building blocks of modern software practice S P Pal
Classes and Objects • Physical entities • User interface components • Rules • Controllers • Protocols • Schedulers S P Pal
Classes • Similar objects constitute a class • ADTs (Abstract Data Types) • Data • Operating functions or behavior Object-based languages like SIMULA67 and ADA offer classes or ADTs S P Pal
Inheritance • Reuse of data and behavior specifications • If C2 is a subclass, its instances inherit data and behavior of instances of C1 • Collection C2 is a subset if C1 • Java supports inheritance and is therefore an object oriented language • C++ supports inheritance from multiple classes • Inheritance provides flexibility in design • Languages like C++ and Java provide inheritance and are called object-oriented S P Pal
Repeated inheritance • Suppose C1 and C2 inherit from B • C3 in turn inherits from both C1 and C2 • C3 may clash on some data item or behavior revealing inconsistencies • Java avoids this facility and C++ circumvents these problems rather clumsily ! S P Pal
Inheritance hierarchy • Multiple levels in the inheritance hierarchy provide ease and flexibility in design • Define several levels of specialized classes as required in the problem domain • e.g., students, PG students, research scholars • Create very complex classes that have too many behaviors and data items S P Pal
Multilevel inheritance Base C1 C2 C5 C3 C4 S P Pal
Polymorphism • Use same name for invoking similar operations irrespective of the types of objects Draw(x1,y1) : draw a point Draw(x1,y1,x2,y2): draw a segment Draw(X1,y1,x2): draw a circle with center at (x1,y1) and radius x2 Graphical-object.draw(…) • Simplified code writing • Code need not be rewritten: extendible S P Pal
Parameter passing • Pass primitive data types by value • No side effects • Functional approach, recursive, stack-based • Pass objects by reference • Big sized objects may cause stack overflow • Objects are persistent entities with global references, not to be copied or destroyed S P Pal