Professional Documents
Culture Documents
By
MD KAMRAN AZAM MD MAZHAAR NOOR MD GHURFAN KHAN MUNDRIKA PRASAD NEERAJ DUBEY NITESH KUMAR [100101128] [100101130] [100101132] [100101135] [100101140] [100101149]
INTRODUCTION
Object-oriented programming (OOP) is a programming paradigm that represents concepts as "objects" that have data fields (attributes that describe the object) and associated procedures known as methods. Objects, which are usually instances of classes, are used to interact with one another to design applications and computer programs.
PROCEDURAL APPROACH
bool MakeDeposit(int accountNum,float amount); float Withdraw(int accountNum,float amount); struct Account { char *name; int accountNum; float balance; char accountType; }; Focus is on procedures All data is shared: no protection More difficult to modify Hard to manage complexity
);
Protection Consistency Allows change
Procedural
Object Oriented
DECLARATION OF AN OBJECT
class Rectangle { private: int width; int length; public: void set(int w, int l); int area(); }; main() { Rectangle r1; Rectangle r2; r1.set(5, 8); cout<<r1.area()<<end l; r2.set(8,10); cout<<r2.area()<<end l; }
CLASSES:
A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object. A class is the blueprint from which the individual objects are created. Class is composed of three things: a name, attributes, and operations. public class Student { }
class Rectangle { private: int width; int length; public: void set(int w, int l); int area(); };
TYPES OF CLASS
Information hiding
To prevent the internal representation from direct access from outside the class.
Access Specifiers
public may be accessible from anywhere within a program private may be accessed only by the member functions, and friends of this class protected acts as public for derived classes behaves as private for the rest of the program
ENCAPSULATION
[OR INFORMATION HIDING]
The encapsulation is the inclusion within a program object of all the resources need for the object to function - basically, the methods and the data. In OOP the encapsulation is mainly achieved by creating classes, the classes expose public methods and properties.
ASSOCIATION
Association is a (*a*) relationship between two classes. It allows one object instance to cause another to perform an action on its behalf. Association is the more general term that define the relationship between two classes, where as the aggregation and composition are relatively special. public class StudentRegistrar { public StudentRegistrar (); { new RecordManager().Initialize(); } }
EXAMPLE OF AN ASSOCIATION
In this case we can say that there is an association between StudentRegistrar and RecordManager or there is a directional association from StudentRegistrar to RecordManager or StudentRegistrar use a (*Use*)RecordManager. Since a direction is explicitly specified, in this case the controller class is the StudentRegistrar.
INHERITANCE
Programs can be built in hierarchical structure from data abstractions that depend on other data abstractions (Components) The object style of data abstraction is the default, not the ADT style Object-oriented programming (inheritance) is based on the idea that data abstractions have much in common Example, sequences (stacks, lists, queues) Object oriented programming builds data abstractions incrementally, this is done by inheritance A data abstraction can be defined to inherit from another abstract datatype, have substantially the same functionality of the other abstract datatype
EXAMPLE OF INHERITANCE
Ability of a new class to be created, from an existing class by extending it, is called inheritance. public class Exception { }
POLYMORPHISMS
Polymorphisms is a generic term that means 'many shapes'. More precisely Polymorphisms means the ability to request that the same operations be performed by a wide range of different types of things. In OOP the polymorphisms is achieved by using many different techniques named method overloading, operator overloading and method overriding,
Method Overloading
The method overloading is the ability to define several methods all with the same name.
public class MyLogger { public void LogError(Exception e) { // Implementation goes here } public bool LogError(Exception e, string message) { // Implementation goes here } }
OPERATOR OVERLOADING
The operator overloading (less commonly known as ad-hoc polymorphisms) is a specific case of polymorphisms in which some or all of operators like +, - or == are treated as polymorphic functions and as such have different behaviors depending on the types of its arguments.
METHOD OVERRIDING
Method overriding is a language feature that allows a subclass to override a specific implementation of a method that is already provided by one of its superclasses. A subclass can give its own definition of methods but need to have the same signature as the method in its super-class. This means that when overriding a method the subclass's method has to have the same name and parameter list as the super-class's overridden method.
SUMMARY
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 one or more hierarchy of classes united via inheritance relationships