Quantcast
Viewing latest article 4
Browse Latest Browse All 5

Division of Responsibility

I once heard two questions in sequence … “For this amount of functions? Why not do everything right in the page code or want to organize not only does one function? ”

So! Complicated to explain, since you have no idea about means Object Orientation Programming. It was the most delicate I could formulate my response.

In response, The Division of Responsibility.

When we create a class, we must bear in mind that the class is responsible to do something within the context of its existence.
We can not have a class FuelInjection() and we use it to turning lamps, for example:

class FuelInjection {
	// method constructor
	function FuelInjection() {
		// implementation
	}

	function Boolean sendFuel() {
		// implementation
	}

	function Boolean turnOnLamps() {
		// implementation
	}
}

Is wrong, is not the responsibility of the Electronics Injection of the Car to torn on lamps, because, mix electricity with flammable fuel, is not the surest way of doing things … it will cause problems.

Now, that does not mean that a class Car() does not need fuel injection…. For this, see this other article below talking about inversion of controls.

Then, create a class, think, plan, and if possible name the same self-explaining its purpose. Recalling that is not to create a class: TornOnCar();

Following these concepts, you can build software using techniques such as functional CleanCode so fluent.

By Paulo Teixeira

Viewing latest article 4
Browse Latest Browse All 5

Trending Articles