5. Data Structure
Exposes data
Usually No behavior
Referred as POJO or POPO in java and python respectively
Can have private fields with public accessors
Can have navigational methods ( ORM, Active Records )
Should not have business logic
13. Pros and Cons
ProceduralCode
easy to add new functions
without changing the existing
data structures
hard to add new data
structures because all the
functions must change.
OOCode
easy to add new classes
without changing existing
functions.
hard to add new functions
because all the classes must
change.
14.
15.
16. Hybrids
Combining Data Structure & Object
Worst of both worlds
Dependencies on attributes
Difficult to add function and class
Difficult to refactor
17.
18. How depth can we go ?
Known as Law of Demeter
A module should hide objects it manipulates
A method ( f ) of class ( C ) can call:
→ method of ( C )
→ method of an object held as instance variable in ( C )
→ method of an object passed as argument in ( f )
→ method of an object created by ( f )
20. References
Clean Code: A Handbook of Agile Software Craftsmanship
by Robert C. Martin
The Clean Coder: A Code of Conduct for Professional
Programmers by Robert C. Martin