DEV Community

loading...

Discussion on: Abstraction and Encapsulation - [OOP & Java #1]

Collapse
jouo profile image
Jashua • Edited

Nice series, I'm going to read all of them :)

OOP:
Model your code based on real-life objects

Personally, I'm not a fan of that concept, take a look at this part of the video from Robert C. Martin, just 35 seconds (51:10 - 51:45)

Collapse
tlylt profile image
Liu YongLiang Author

Hey,

I watched the talk and found some interesting ideas that you are pointing at, and I agree with them.

Is-a relationship is somewhat a lie

  • A Square class represents a square.
  • A Rectangle class represents a rectangle.
  • In real life, a square is a rectangle. But in code,
  • "The representatives of things do not share the relationships of the things that they represent."

And

OO is about managing dependencies by selectively inverting certain key dependencies to prevent rigidity, fragility and non re-usability.

In a sense, I feel that OO does model the code based on real-life objects, just that those objects are now more independent that they really are. It is definitely not a 100% copy-paste from the real world.

Also, I like the part on the open-close principle.
Like what was mentioned in the video, we are hardly able to predict what clients/consumers may want now and in the future. Even if we can safeguard ourselves from possible changes that we are able to predict at the point of coding, (e.g. that clients may want to add an Oval in our classes of shapes), there are other aspects which will eventually force us to change our design. In this case, open-close principle is simply our desire and our hopes and dreams. He mentioned that we can try to release early and get a sense of consumer thinking behind a product and therefore implement accordingly. That might work to an certain extent.
Like most things in life, human beings are the source of failure. 😂

Thanks for sharing!

Collapse
jouo profile image
Jashua

Yea! I completely agree :)

Your series are really good, hands down, are design patterns in your list of things to write about?

Thread Thread
tlylt profile image
Liu YongLiang Author

Thank you for your kind words 😄

I did plan to write about design patterns and but maybe not anytime soon due to my other commitments. However, my primary source of information on design patterns is this website(Do check it out if you haven't).

Cheers!