OO 101
Post contains elementary object oriented programming information.
Do The Simplest Thing That Could Possibly Work
Submitted by curtisrcooley on Sat, 04/11/2009 - 15:37I was reading these posters and the one on simplicity made me think. It brilliantly summarized it with a simple concept: do the simplest thing, not the simplistic one. But what is the difference?
- Runs all the tests
- Says everything once and only once (DRY)
- Expresses all the ideas you want to express
- Minimizes classes and methods
Why You Should Program To Interfaces Part I
Submitted by curtisrcooley on Sun, 03/22/2009 - 19:52The Open Closed Principle (OCP)
The Open Closed Principle (OCP) states that a system should be open to extension and closed to modification. In other words, it should be easy to add new functionality by not changing existing code. If you program to interfaces, it is much easier to follow the OCP.
Calculator No OCP
Let's build a very simple calculator.
class Calculator {
int add(int x, int y) {
return x + y;
}
}
