ghanshyam.mirani
ghanshyam.mirani

Reputation: 3101

Issue related to concept of abstraction in OOPs

I was reading OOPs Concepts from internet using articles.

In one of article, I have read following about abstraction:

If we have a method named "CalculatePrice" inside the "Billing" class, we are not concerned about the calculations inside the "CalculatePrice" method. We just pass the necessary parameters and get the output. We hide the implementation of "Calculate Price".

so my question is : In C#, we are using dlls and namespace and calls the specific methods. can we say that, dlls and namespaces are the concept of Abstractions ??

Thanks

Upvotes: 1

Views: 227

Answers (3)

David Arno
David Arno

Reputation: 43264

Interesting that there are four answers all saying "no". In reality, the answer is "sometimes". If the implementation of CalculatePrice relies on another class, which is marked as internal, then its assembly does form part of the abstraction, since internal classes are only accessible to other classes in that assembly.

Namespaces in .NET do not form part of any abstraction though. In other languages they can, as internal can be tied to namespaces, but that is not how .NET languages work.

Such information hiding is the most basic form of abstraction though. C#'s most powerful abstraction tools are interfaces, support for dependency injection and its treatment of methods as values. If you are interested in understanding more about abstraction in C#, they are the three areas to focus on.

Upvotes: 1

Kjartan
Kjartan

Reputation: 19151

No.

You should generally just think of dll-files and namespaces as ways to organize your projects.

The abstraction of CalculatePrice consists simply of the "hiding" of it's logic inside the method. When another piece of code calls the method, it does not care what happens inside it - it is only interested in the result.

Abstractions in C# (and .Net in general) are made using things like Classes, Interfaces, Abstract Classes, and method and properties that are defined and/or implemented in these.

Your focus should be on these concepts, and on how they are used together in different "patterns" to solve various types of problems.

To expand just a little on your example: If CalculatePrice was defined in an interface, then calling code would "talk to" that interface, without caring about what was behind it. An implementation of that interface - the code that actually performs the logic - could be anything. It could change, and keep changing, as long as it fulfills the requirements (the "contract") defined in the interface, since that would allow the calling code to keep using it.. and that is how abstraction works in C#.

Upvotes: 3

Lotok
Lotok

Reputation: 4607

so my question is : In C#, we are using dlls and namespace and calls the specific methods. can we say that, dlls and namespaces are the concept of Abstractions ??

No.

Upvotes: 0

Related Questions