Someone has already solved your problems.
This is how the Head First: Design Patterns book starts. Motivating, isn’t it? Maybe this as far as OOP, or object-oriented programming is concerned. OOP has been around for quite a while, so chances are someone has already encountered a similar problem and probably solved it.
The goal in OOP is to develop maintainable, reusable code with high cohesion and low coupling. High cohesion refers to the measure of how much the methods have in common with the class they are in. An example of a low coupled class is something like this:
As you can tell, the SendEmail() has no business being there, which makes this a low-cohesive class.
Low Coupling is where one class has a low degree of dependency the inner workings of a different class. An example of a high coupling would be a Class A that got a temperature reading from a Thermostat class. If Class A needed to be changed because the Thermostat class changed how it calculated the temperature, these two classes would be highly coupled.
Design patterns will help you avoid these types of anomalies and in the series of post following, I will go into detail describing each one, following the texts and examples from a favorite book of mine: Head First: Design Patterns.
You can follow these series under this post tag: /tag/design-pattern-series/