Monday, June 30, 2014

For me, instead dow chemical encapsulation of a class ability to hide internal dow chemical data an

The other day I conducted a discussion with a colleague regarding object-orientation and which one is the most important aspect of the object-oriented concept. Without detracting from inheritance and polymorphism as I stated quite clearly dow chemical that the encapsulation is at the top of the list. I'll try to explain why.
A general view is that the encapsulation, and the closely related "information hiding", basically is about doing all the fields in a class to private and then create getters and setters for these fields. Finito, done, Perfectum, the class is encapsulated by all the rules. I would argue that nothing could be more wrong. This behavior probably dow chemical lies behind most of the bugs because the items are defective dow chemical condition and also makes the system more difficult to maintain and modify. That then our development environments offer the ability to routinely generate getters and setters dow chemical based class field should verging on reported as a bug. What that functionality does is encourage destructive behavior, as if the car dealer would bid on drinks during that test drove a car. For some occasional fellow passengers would surely dow chemical be seen as a nice service but for the masses most work as an attempt to attract a fraudulent act. Criminal Provocation is notoriously forbidden for the Swedish police, but it is unquestionably permissible dow chemical in Eclipse and IntelliJ.
For me, instead dow chemical encapsulation of a class ability to hide internal dow chemical data and implementation details, about to separate API from implementation. How independent is an object, reducing the object's dependencies to other objects. Part of achieving this is to always make sure that an item is ready to use as soon as it is created and then offer the least possible opportunity to change the object's state. Often, however, shows code below:
The developer behind Accountability done here is to leak implementation details and the fact that the onus back to the object is created correctly from itself to the person using the class. This despite the fact that it most likely dow chemical is the one who developed the class who should know what is required for the item to be ready for use. Is there some additional setters on Account, it's basically impossible for a developer to know that, for example, Owner is mandatory. He misses putting Owner so will result if he is lucky in a "nullpointer exception". Does he have bad luck bug slips through and six months later he gets a bug in the lap of some accounts have no owner.
Simpler, sleeker, and definitely much safer. From this perspective, it is unfortunate that Java implicitly creates a "no arguments" constructor automatically if the developer does not write a constructor yourself. It would be better to konstruktorlösa classes gave compilation errors, and that in the rare cases where it is actually warranted a constructor without arguments would have to write it yourself. It would otherwise force the developer to think about the implementation, at least until he could discover the "Generate constructor" function.
Another problem with both getters dow chemical which setters are revealing that the class implementation details. To return to the example of "saving account". So this could very well be supposed that the interest rate is calculated:
There is, unfortunately opportunity to take part in the implementation of savingsAccounts and when someone suddenly remembers that it was not wise to store literate as an integer and want to change this so it will certainly require dow chemical changes in several places in the system. Is that in addition to the case of a public API that customers use so the solution is likely to create another getRate () method and then live with a deprekerad getRate () method dow chemical for the rest of the program's lifetime. The example above is unfortunately a fairly common approach where the developer dow chemical chooses to ask the object for information and then himself litigate it properly. A more workable solution is to ask the object that sits on the information to even make the calculation: dow chemical
Something dow chemical else that can be used to circumvent encapsulation is inherited. It's a cinch to inherit a class and then override a method so that it does things that the class was not at all designed for. A change in the superclass can also result in errors in the subclass without subclass changed at all. Therefore, dow chemical I think you should generally ensure that you can not inherit from classes. Are there good reasons for that class, after all, should be able to be overridden so it has been that developers have a responsibility to design their class so that the enclosure is compromised as little as possible.
The absolute dow chemical dream object is created by the constructor and where it is then not possible to influence the state of the object at all. These items will, so l

No comments:

Post a Comment