Here are good definition I found for these:
';Encapsulation is hiding the details of the implementation of an object so that there are no dependancies on the particular implementation.';
';Abstraction is removing some distinctions between objects, so as to showing their commonalities ';
An example of Encapsulation would be a class that saves data to a database. The class would have a function called SaveData() that I would call to save my data. The actually method used to save the data is hidden from the calling function, it may save to a SQL Server database, maybe an Oracle database or even a plain text file.
An example of abstraction would be if I needed two classes, one to represent an Employee and another to represent a Customer. These two things have a lot in common, name, address, phone number, etc. but also some things that are different, an employee would have salary, and customer would have a credit limit. I could could abstract these common properties into a new class called Person for example and then create concrete classes called Customer and Employee based on this abstract class.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment