One of the most important but neglected object oriented principles.
When we do interviews or talk about Object Oriented Programming we always talk about the following features:
In one of the recent interviews I was conducting for a .Net developer position I asked the question, what is association in OOP? And the candidate said I have never heard of it.
I was shocked!!!
Maybe because everyone is asking the same repetitive questions on OOP.
- What is Abstraction?
- What is Encapsulation?
- What is the difference between the 2?
- What is Polymorphism and its types?
Even for interview preparation we prefer to read on Google and prepare ourselves for the job.
So, somehow I felt is is one of the important features but it is neglected. Let us understand what association means and how it is related to our daily programming.
Association
I will say it can be any relation between more than one object in the world.
For example I am related to my parents in a Parent/Child relationship.
To provide more technical examples for you:
- A class can have one or more child classes, for example Exception class.
- An interface can implement one or more interfaces, for example IEnumerable.
- In the Entity Framework one entity can be related to other entities via navigation properties.
- In SQL, a table will have a foreign key reference with other tables in the same database.
Now, we realize we use it in daily practice but maybe we don't understand its importance.
This helps very much when we design any new system/software in the initial stage or also when there is a change request and we need to do an impact analysis.
I hope you like this article. I will come up with few more day-to-day useful articles like this.