-2

I just wanted some feedback on my definitions of these terms.

Abstraction - only showing relevant information and hiding implementation details. Interfaces and abstract classes are an examples of abstraction. Allows a user to use some form of functionality without knowing the inner workings. For example, the HashSet class provides put() and get() methods... As a user I do not need to know how the HashSet class implements these methods, I just need to know the relevant details such as the method names and parameters. Abstraction reduces overall complexity of a software system.

Encapsulation - the process of binding the data and operations performed on that data into a single unit. OOP classes are a good example of this - all the data and methods performed on that data are contained within the class. Furthermore, encapsulation allows us to hide the state of an object by making attributes of an object private and only allowing the object itself to perform actions on the attributes via public methods. Encapsulation helps with both security and modulisation.

Polymorphism - the ability for an entity to take on multiple different forms, based on the context. Examples of polymorphism are runtime and compile time polymorphism. Runtime polymorphism is achieved by method overriding, while compile time polymorphism is achieved by method overloading.

Inheritance - allows for common attributes and functionality to me shared amongst different entities. This supports code reuse and reduces complexity.

  • You're dead wrong on inheritance. But why focus on definitions? Any interviewer worth their pay will ask you about the practical advantages and applications of these techniques. If you say "Encapsulation helps with security", you'd better be able to explain or they'll think your talking out of your *ss. – D Drmmr Nov 18 '18 at 13:17
1

You're missing that inheritance is a form of polymorphism. Others include composition and delegation, prototype, duck typing, and interface compliance. You're focusing inheriting subclasses ability to share parent code while ignoring the most powerful thing inheritance does: allow you to change code behavior without a rewrite.

Polymorphism makes it easier to change code behavior without having to change proven working code.

Encapsulation makes reading code easier. It is much better defined as data hiding. It's not about units or security. When the only code that can manipulate the data is in the same place it's easier to predict what that data will be and when. Ideally encapsulation ensures that the data is only used to change behavior. Not as a temporary storage before sending the same data elsewhere, unchanged.

Abstraction makes interfaces easy to use. It doesn't really reduce overall system complexity. It reduces the complexity you have to deal with from any one perspective within the system. The system is still free to be wildly complex. You just don't ever have to deal with that all at once in a properly abstracted system.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.