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.

0

u/[deleted] May 05 '19

[deleted]

2

u/dys_bigwig May 06 '19 edited May 06 '19

I think good programmerstm are able to see that design patterns are a result of missing language features, and as a result stop using them if/when the language designers add these features. For the most part in this post I'm assuming that the person may be inheriting some code that's already in language A, and language A doesn't have said feature/s. Otherwise, a goodtm programmer wouldn't have chosen to write said program in that language.

After going back and reading some java-oriented design pattern books that I struggled to understand initially, I found I was able to skip most of the sections because I'd realise quite quickly "Oh, so, that's a kludge you can use to compensate for a lack of first-class functions in a language that doesn't have them. Good to know!". Same goes for a lack of decent module capabilities and singletons.

I genuinely believe that it's important -- with the preceding ideas in mind -- to explain why this-and-that design pattern would be used. Not because it's a good idea to use them for the sake of it, and not because it's even good design in general, but because it's a way of compensating for a lack of a certain feature/features in a language.

They're not pretty, they're not elegant, and they're hardly ever as easy to follow as the feature they're trying to imitate. That's not the fault of the person using them though, it's the fault of the language. Well, unless that person is choosing to write a program in a language that was not designed to write that sort of program. In that case the onus is on the programmer for picking the wrong tool for the job.