Abstraction vs Encapsulation

Below is the difference:

Encapsulation

Abstraction

Encapsulation is the act of packing data and function into a single unit.

Abstraction means representing the essential features without representing/hiding the background details.

Eg: Class

Eg: abstract class, interface.

Encapsulation is achieved using abstraction.

It is achieved using access modifier.

 

 

 

 

Here if we make Validate() and CreateBDObject() methods public and let the client call these method before calling Add() then it will be showing extra information to user as these two methods will only be called if we want to perform Add operation.

 

So if we follow abstraction then we make these two methods private and include them in Add() method. This way only the essential features are shown to the client and hiding the background details.

Leave a comment

Filed under C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s