Association in OOP

One of the most important but neglected object oriented principles.

                              object oriented principle

When we do interviews or talk about Object Oriented Programming we always talk about the following features:

                              Object Oriented Programming

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
                                 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:

  1. A class can have one or more child classes, for example Exception class.

  2. An interface can implement one or more interfaces, for example IEnumerable.

  3. In the Entity Framework one entity can be related to other entities via navigation properties.

  4. 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.


Similar Articles