Things You Might Miss
Things You Might Miss
miss
Interview is not a Question-
Answer thing, it’s a
Discussion
- Use your Interviewer’s brain as much as
possible
- Interviewer is looking for a coworker with
whom he can be free, discuss anything
Encapsulation
vs
Abstraction
- Encapsulation is about disallowing access or
knowledge to internal structures
- Abstraction is about separating interface from
implementation
class DataStore{
List<Int> numbersList;
public DataStore(){
numbersList = new ArrayList<Int>();
}
public List getNumbersList(){
return numbersList;
}
public void setNumbersList(List<Int> list){
numbersList = list;
}
}
See how
- Encapsulation is done by disallowing access to underlying List
- Abstraction is done with get and add methods
Inheritance
vs
Composition
- Use it based on logical relationship between
classes : Inheritance when is-a and
Composition when has-a.
- Don’t simply use Inheritance for code-reuse or
polymorphism
Abstract Class
vs
Interface
- Whenever there is hierarchy use class
- For interfaces for with the behaviour that can
applied anywhere
- E.g. comparable, movable
Primitive Obsession
- "Just a field for storing some data!" the
programmer says
- One field adds up every time and creating bad
smells
- Try grouping them and there borns your
object
Objects
- OOP code is not only having classes
- An object should have behaviour
- Remember “Object = state + behaviour”
Design a Parking Lot
- Vague question
- http://martinfowler.com/tags/clean%20code.html
- https://www.cs.helsinki.fi/u/luontola/tdd-2009/ext/ObjectCalisthenics.pdf
- http://ptgmedia.pearsoncmg.com/images/9780132928472/samplepages/0132928477.pdf
-