Encapsulation, Polymorphism, Agreggation / Composition, Overloading, Inheritance vs Composition, DRY, Dependency Injection, Delagation, Law of demeter, Principle of leas knowledge,
2. 1/9 What is Encapsulation ?
Much of object programming is centered on
minimizing the ripple effects caused by changes to a
program. This is done simply by keeping details
secret The principal ways of doing this are:
- minimizing visibility - private fields, package-private
classes (grouping into 1 domain package:
entity,repository,service,controller)
- generic references (polymorphism) - using high
level references (interfaces or abstract classes)
instead of low level references (concrete classes)
3. 2/9 What is Polymorphism ?
The point of polymorphism is that you can subclass a
class and the objects implementing those subclasses
will have different behaviors for the same methods
defined in the superclass (and overridden in the
subclasses).
4. 3/9 What is Aggregation / Composition ?
has-a relationship
5. 4/9 What is Method Overloading ?
If a class has multiple methods by same name but
different parameters
6. 5/9 Inheritance vs Compositions ?
inheritance - Java doesnt support multiple inheritance
(till java 8 , where we have default methods )
composition - Use private members
inh - you need super class instance
comp - easy to create Mock Object representing composed class
inh - it breaks encapsulation, when behavior of super class changes,
functionality in sub class may get broken
comp - you are flexible enough to replace implementation of
Composed class with better and improved version.
inh - Inheritance makes much sense like when a genuine parent child relation exists
comp
- In Decorator pattern, we dont extend any class to add additional functionality
Instead we keep an instance of the class we are decorating
and delegates original task to that class after doing decoration
7. 6/9 What is DRY ?
avoid duplication for functionality , use dependency injection if needed.
but you can repeat same code (ie user authorization) for different functionalities in micro services or micro functionalities
8. 7/9 What is Dependency Injection ?
Class injected by DI framework is easy to test with mock object
Easier to maintain because object creation code is centralized in framework
Done in Spring via proxies
9. 8/9 What is Delegation ?
delegate tasks to ie:
equals, hashcode methods, thread pools
do not do it yourself on client side
10. 9/9 What is Law of Demeter / Principle of least
knowledge ?