Welcome to my blog

I blog my interests and opinions here.

Showing posts with label OOAD. Show all posts
Showing posts with label OOAD. Show all posts

Monday, July 18, 2011

What is polymorphism really!

It's been a while I blogged. With a new baby and things that come with it life kind of has become pretty hectic.

I always thought that polymorphism was the ability to implement the same behavior in different ways. An Animal would move (public void move()) but the way a Cat would implement move would be different from the way an Elephant would implement move. But that is not the case, polymorphism is the forcing the Cat class and Elephant class to implement move() method in their own way by having them implement an IAnimal interface with a public void move(); method. It is inheritance and method implementation that we see here. Method overriding does not mean the classes are exhibiting polymorphic behavior. See the Wiki for more details http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming

Wednesday, November 10, 2010

Object oriented analysis and design

I am a strong believer in thinking object oriented. Given a real life problem, the solution becomes clearer when it is broken down using the OOAD principles Abstraction, Polymorphism, Inheritence and Encapsulation (A PIE).

Although several books and materials on the internet explain these concepts in a more technical manner, I think that things are clearer if we looked at it from a layman's perspective using an example of a small business.

Abstracion: To be more specific lets look at the payroll processing system in a small business. Any payroll processing system would have some common operations such as check balance and process payroll. These general operations could be classified as abstraction.

Polymorphism: In the payroll processing system the operation process payroll could be handled in different ways. The first one being process payroll using direct deposit and the second being process payroll with check. This could be classified as polymorphism.

Inheritence: In the payroll processing system there could be two different branches one in Arizona and the other in New York. Both the branches would process payroll by inheriting the common behavior from the parent but implement the payroll processing in different ways (as the state taxes etc. could be different). This could be classified as inheritence.

Encapsulation: In the payroll processing system when the payrols is being processed for an employee the information such as state taxes would be encapsulated. Such a data hiding technique could be classified as encapsulation.

As we can see the complex payroll processing system in not so complex anymore when looked at using the "A PIE" principle of OOAD.