In Object Oriented Paradigm, System is based on objects interacting with other objects.
Benifits of OOP:
Easy to Maintain
Easy to Extend and Reuse
Easy to Understand
In order to achieve this, there are Certain principle in OOP to follow in Design and Implementation of System. Those are following:
Objects Have State, Behaviour and Identity
Encapsulation and Datahiding
Inheritance and Generalization
Polymorphism and Latebinding
Delegation and Propagation
Open Closed Principle
P2I(Program to Interface)
Object Oriented Analysis and Design:
Analysis: Analysis means to find out what is needed or what are the client requirements. What the problem is; It is like listening to the problem in some conversation.
Design: Design is to make the needs happen or make the requirements functional reality. It is to find out the solution for the problem. It is same as giving suggestion after listening to a problem while in conversation
As in real world, objects have relationships same is in case of Objects in OOP.
Type of RelationShip between classes:
Types of Association
Unidirectional and Bidirectional
Aggregation
Composition
Reflexive
Association Classes
Association "decoration" : name, roles, multiplicities
Static Binding and Late(Dynamic) Binding:
static binding is a compile time operation while dynamic binding is a runtime. one uses Type and other uses Object to bind.
static, private and final methods and variables are resolved using static binding which makes there execution fast because no time is wasted to find correct method during runtime.
Overloaded method are bonded using static binding while overridden methods are bonded using dynamic binding at runtime.
Open-Close Principle in JAVA:
Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.
This Principle is important in case of dynamic and growing application and hence to save programmers effort as change a previously tested code can cause a lot of overhead hence we should always try to extend the code for new requirements which will fulfill new requirement without changing in the previous working version.
Polymorphism supports use of the Open-Closed Principle: The part of our code that is established and tested is closed to modification (change), but at the same time the system remains open to changes, in the form of extensions.
Propagation and Delegation:
An action can be passed to other classes in OOP this is called Propagation and the actual realization of the responsibility is called Delegation. A class can express functionality in its interface, but it delegates responsibility to an associated class to carry out the action. The responsibility for the action can propagate through a hierarchy.
Diamond Problem:
In programming languages in which multiple inheritance is supported a problem arises when inheriting from multiple classes to one class. Suppose a class D inherits from class B and C which inherits from super class A where both class B and C have a method go() having same signature then there will be a problem while deciding if D will inherit go() from B or C this problem is called Diamond Problem.
As a solution to this problem JAVA (previous than 8) can inherit only from once implementation but can inherit multiple times from types(Interface).
Benifits of OOP:
Easy to Maintain
Easy to Extend and Reuse
Easy to Understand
In order to achieve this, there are Certain principle in OOP to follow in Design and Implementation of System. Those are following:
Objects Have State, Behaviour and Identity
Encapsulation and Datahiding
Inheritance and Generalization
Polymorphism and Latebinding
Delegation and Propagation
Open Closed Principle
P2I(Program to Interface)
Object Oriented Analysis and Design:
Analysis: Analysis means to find out what is needed or what are the client requirements. What the problem is; It is like listening to the problem in some conversation.
Design: Design is to make the needs happen or make the requirements functional reality. It is to find out the solution for the problem. It is same as giving suggestion after listening to a problem while in conversation
As in real world, objects have relationships same is in case of Objects in OOP.
Type of RelationShip between classes:
Association
Dependancy
Inheritance
Unidirectional and Bidirectional
Aggregation
Composition
Reflexive
Association Classes
Association "decoration" : name, roles, multiplicities
Static Binding and Late(Dynamic) Binding:
static binding is a compile time operation while dynamic binding is a runtime. one uses Type and other uses Object to bind.
static, private and final methods and variables are resolved using static binding which makes there execution fast because no time is wasted to find correct method during runtime.
Overloaded method are bonded using static binding while overridden methods are bonded using dynamic binding at runtime.
Difference Between Procedure Oriented Programming (POP) & Object Oriented Programming (OOP):
Procedure Oriented Programming | Object Oriented Programming | |
---|---|---|
Procedural programming uses a list of instructions to tell the computer what to do step-by-step. | Object-oriented programming, or OOP, is an approach to problem-solving where all computations are carried out using objects. | |
Approach | POP follows Top Down approach. | OOP follows Bottom Up approach. |
Data Moving | In POP, Data can move freely from function to function in the system. | In OOP, objects can move and communicate with each other through member functions. |
Expansion | To add new data and function in POP is not so easy. | OOP provides an easy way to add new data and function. |
Data Access | In POP, Most function uses Global data for sharing that can be accessed freely from function to function in the system. | In OOP, data can not move easily from function to function,it can be kept public or private so we can control the access of data. |
Data Hiding | POP does not have any proper way for hiding data so it is less secure. | OOP provides Data Hiding so provides more security. |
Overloading | In POP, Overloading is not possible. | In OOP, overloading is possible in the form of Function Overloading and Operator Overloading. |
Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.
This Principle is important in case of dynamic and growing application and hence to save programmers effort as change a previously tested code can cause a lot of overhead hence we should always try to extend the code for new requirements which will fulfill new requirement without changing in the previous working version.
Polymorphism supports use of the Open-Closed Principle: The part of our code that is established and tested is closed to modification (change), but at the same time the system remains open to changes, in the form of extensions.
Propagation and Delegation:
An action can be passed to other classes in OOP this is called Propagation and the actual realization of the responsibility is called Delegation. A class can express functionality in its interface, but it delegates responsibility to an associated class to carry out the action. The responsibility for the action can propagate through a hierarchy.
Diamond Problem:
In programming languages in which multiple inheritance is supported a problem arises when inheriting from multiple classes to one class. Suppose a class D inherits from class B and C which inherits from super class A where both class B and C have a method go() having same signature then there will be a problem while deciding if D will inherit go() from B or C this problem is called Diamond Problem.
As a solution to this problem JAVA (previous than 8) can inherit only from once implementation but can inherit multiple times from types(Interface).
No comments:
Post a Comment