r/programming • • May 05 '19

10 OOP Design Principles Programmer Should Know

https://hackernoon.com/10-oop-design-principles-every-programmer-should-know-f187436caf65
2 Upvotes

44 comments sorted by

View all comments

25

u/glacialthinker May 05 '19 edited May 05 '19

I tend to hate OOP because of the poor quality of code which results: 10% of the code being relevant to the problem, the rest being boilerplate, excessive interface and encapsulation fluff (which also has to change as the program evolves anyway), redundancy because of object hierarchies tied to types/data or functionality hidden by abstraction, and more...

However, this set of principles (the article) can lead to much better object-oriented code, and most of them can apply to programming in general. I'd rather work with programmers following these principles (though reserving heavy encapsulation for library or external interfaces) than working with a tool-belt full of design-patterns.

1

u/devraj7 May 05 '19

Did it ever occur to you the bad OOP code you're seeing has a lot more to do with the quality of the programmers who wrote it than OOP per se?

4

u/glacialthinker May 05 '19

That's kinda what I'm saying, right? Are people only reading my first paragraph?

8

u/[deleted] May 05 '19

I think the problem is that your second paragraph doesn't logically follow from the first.

In the first paragraph says that you hate OOP because of the poor quality of code that results. But in the second paragraph, you say that better programming techniques lead to higher quality OOP code.

These are contradictory statements.

3

u/CODESIGN2 May 05 '19

I think they said that better techniques barring heavy encapsulation except around service boundaries make higher quality code regardless of paradigm.

It's not contradictory unless you have your encapsulation == oop goggles on. You can encapsulate in a number of ways starting from the humble function for behavior and data (with constant / idempotent being the default without static or other clever language features or libraries being used).

def pi():
    return 0 + 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899

def to_radians(degrees):
    return degrees * (pi / 180)

def to_degrees(radians):
    return radians * (180 / pi)

That is to say without knowing the formula you could encapsulate the algorithm and pass by name, or simply call by name (more primitive, but passing by name usually requires functions to become object or object-like)

1

u/[deleted] May 05 '19

Well yeah, but that isn't an argument for why OOP tends to produce poor quality code. Good coding practices are practically universal.

1

u/CODESIGN2 May 06 '19

Put another way (as someone that likes OOP but doesn't put it on a pedestal)

OOP gives you the scissors, you choose to run with them instead of cutting things with them. Holster your scissors if you plan on running.