samedi 30 décembre 2017

OOP Abstraction: multiple, yet rather distinct, contexts?

I've been doing some research on OOP concepts and am having a bit of an issue in trying to understand what exactly Abstraction is. I've gone over numerous Stack Overflow posts on the topic but haven't really been able to pinpoint a satisfying answer.

I've seen a lot of discussions on the differences between Abstraction and Encapsulation, and naturally started started thinking about Abstraction in terms of hiding how a particular class works and providing abstraction through the class API. Here are some posts that steered me in this direction:

However, as I read through more posts, I noticed answers portraying Abstraction in an Inheritance context, specifically using interfaces and abstract classes to provide an Abstraction of a certain entity (class). I assumed Abstraction given in this manner would allow developers to extend new objects appropriately according to the "guidelines" outlined by this Abstraction. Here are some posts that lead me in this direction:

I'm not sure if I'm just completely missing the point here, but it's getting pretty confusing because every answer seems to add a slight variation to the mix. I definitely see why both contexts are crucial in Object Oriented Programming, but I really wanted a clear-cut definition of what Abstraction is.

Which brings me to my point: does Abstraction work in multiple contexts? Does Abstraction portray both of these concepts?

  1. Hiding away "unnecessary details" as done through interfaces and abstract classes

    • Providing an abstraction on an class to be created through interfaces and abstract classes. We can provide an interface of IPet which would act as an abstraction of a Dog class. Additionally, maybe providing an Animal base class as an abstract class to provide an additional abstraction?
  2. Abstracting the implementation of a class by exposing it through the class API

    • given a Dog class, we just need to know that it has a feed() function as part of its API, and call that function to feed it without knowing how the feeding is actually done. This provides abstraction on the Dog class and lets us easily interact with the class

One of the links I've included above contains the following quote by Matthew Watson that says:

"The problem is that there are no precise definitions for these concepts, and the words themselves have multiple meanings even within the context of object orientation."

Is it just that Abstraction is so abstract, even the definition is abstract :P? Thanks for any guidance in advance!

Aucun commentaire:

Enregistrer un commentaire