Coffeehouse Thread

12 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Does abstraction (Oops Concept) means using Abstract class.....people are really confused about this

Back to Forum: Coffeehouse
  • User profile image
    Surendiran Bala

    Does abstraction means implementing or using Abstract class in C#.

    Ref: http://forums.asp.net/t/1258933.aspx/1

    In the above forum the people are giving different views..such as

    One guy says Abstraction : Abstraction means hiding the complex thing and showing essential thing(like TV or Car)

    Another guy says Abstraction :Abstraction means that you have some class that is more common than others that extend it.

    Which one of the above statement is true...

    If the first statement is true hiding the complex thing..please give us real example with completed code..

    else if the second statement is true please explain it with sample code

  • User profile image
    blowdart

    "The notion abstraction is to distill a complicated system down to its most fundamental parts and describe these parts in a simple, precise language."

    It doesn't mean using an abstract class, although that's one way to do it. It's taking the core functions of something and exposing them to a developer.

    So to take your car example, you might have a method called Drive. That's a core function - and doesn't concern itself with how to turn the car on, how to change gear and so on. It has abstracted those things which may be different for every implementation and just exposed the fundamental Drive function. The Drive function could be inherited from an abstract class, or even from an interface.

    This is OOP101, and far better explanations exist.

  • User profile image
    Surendiran Bala

    Hi thanks for your quick response....

     

    I dont understand the concept here...people will say abstraction means hiding the complexity and showing the only the essential feature...

    some people will say Abstraction means that you have some class that is more common than others that extend it.(its look like inheritance)...

    i just need some sample code which explains hiding the complexity and class that is more common than others that extend it.

     

    Could you help me with that...

  • User profile image
    cbae

    Abstraction and inheritance really don't have anything to do with each other. You can create an abstraction layer without involving any interfaces or classes (abstract or otherwise) at all.

  • User profile image
    evildictait​or

    I dont understand the concept here...people will say abstraction means hiding the complexity and showing the only the essential feature...

    Abstraction isn't about hiding complexity - often it's quite the reverse. Abstraction is taking something specific and making it less specific.

    Normally speaking abstracted concepts are more complicated to understand, but once understood do an entire set of things more powerfully that previously you only had specific examples for.

    To give you an example, suppose you are building a function which requires some number of strings. Now a colleague of yours might say "I wish to call your function passing an array of strings". Another colleague might say "I wish to call your function passing a List<string>" and another might say "I would like to call it passing a databound list of strings which dynamically gets more strings from our database".

    Now you could design your function (let's call it bar) as:

    bar(string[] foos) { ... }
    bar(List<string> foos) { .. }
    bar(DataboundListOfStrings foos) { ... } 

    Or you could apply abstraction, and say actually you just want a collection of string - you don't particularly care how it's stored. The abstracted form would look something like this:

    bar(IEnumerable<string> foos) { ... }

    On face value this is more complicated than any single previous case. Rather than just doing foos[i] to get the i-th element out of the array or list, you have do iterate through via the complicated interface - but despite your one function being more complex than a single previous instance, it combines all of the previous implementations into one glorious do-it-all function, which is the essence of abstraction.

     

    I think if you're struggling with the word "abstraction", then perhaps a better word to use is "generalisation", whereby you make something less tied to a specific way of doing something if you don't need to.

  • User profile image
    magicalclick

    Abstraction means you buy a BMW and you have no idea how it works, but there is a accelerator to step on and by its documentation, that means your engine will work harder.

    You know what it does, but, you don't have to know how. Doesn't matter it is magic or not.

    Leaving WM on 5/2018 if no apps, no dedicated billboards where I drive, no Store name.
    Last modified
  • User profile image
    Surendiran Bala

    @evildictaitor:

    so from the above comments i can easily say abstration is just a concept in OOPS and it doest not mean using Abstract class in C# code..Right ?

  • User profile image
    Richard.Hein

    Abstract Cat

  • User profile image
    AndyC

    @Surendiran Bala: Sort of. Abstraction is just a concept in general, it's not specific to OOP (although OOP puts a greater emphasis on the idea of abstraction).

    Abstract classes are an entirely different thing altogether, they're more to do with generalisation and polymorphism.

  • User profile image
    spivonious

    , magicalclick wrote

    Abstraction means you buy a BMW and you have no idea how it works, but there is a accelerator to step on and by its documentation, that means your engine will work harder.

    You know what it does, but, you don't have to know how. Doesn't matter it is magic or not.

    No, that's encapsulation. Abstraction would be buying a BMW. a Ford, and a Cadillac and knowing that if you press on the gas, the car will go, regardless of brand.

    Encapsulation:

    Car bmw.Accelerate();

    Abstraction:

    Bmw:Car, Ford:Car, GM:car

    Car bmw = new Bmw();

    bmw.Accelerate;

     

    A slight difference, but a difference nonetheless.

  • User profile image
    magicalclick

    @spivonious:

    oops, that's my bad. You are right. I got mixed up here.

    Leaving WM on 5/2018 if no apps, no dedicated billboards where I drive, no Store name.
    Last modified
  • User profile image
    cbae

    Encapsulation has two different meanings vis-a-vis objective oriented programming. The first is ability to "bundle" both data with behavior. The second is ability to control accessibility of an object (or class') members (e.g. private, protected, public, etc. access specifiers in C#). 

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.