Timeline for What are the disadvantages of self-encapsulation?
Current License: CC BY-SA 3.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 12, 2017 at 7:31 | history | edited | CommunityBot |
replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
|
|
| Nov 14, 2013 at 18:06 | vote | accept | Dave Jarvis | ||
| Nov 13, 2013 at 1:26 | comment | added | Karl Bielefeldt | A crash that a developer can't ignore is better than a subtle data corruption issue he doesn't notice. | |
| Nov 12, 2013 at 22:02 | comment | added | Dave Jarvis | I disagree about making issues harder to debug. By consistently applying self-encapsulation, it makes the entire system easier to debug. Add a stack trace in the accessor to show exactly when the unexpected value was set and how. Combined with Aspect Oriented Programming, debugging the system becomes trivial. I cannot imagine a manager saying, "The system should crash for our users." | |
| Nov 12, 2013 at 21:52 | comment | added | 17 of 26 | In the case of data not being initialized properly, I'd much rather have a crash at the time of the bad data being encountered rather than silently using an incorrect value. The incorrect value will manifest itself later as a problem that's located away from the original source. This makes things much harder to debug. | |
| Nov 12, 2013 at 21:38 | comment | added | Dave Jarvis |
While developers must handle unexpected values, eliminating null pointer dereferences would help produce crash-free software (other flaws would still be present). You mention needing to handle uninitialized values, but self-encapsulation ensures all values are initialized (i.e., never null), which means that no extra code is required to handle the null (i.e., uninitialized) case.
|
|
| Nov 12, 2013 at 21:19 | comment | added | Dave Jarvis |
+1. I neglected to mention that the createDefaultValue() method is used, lazily, to provide a valid non-null value -- this method abstracts how the value is initialized while allowing subclasses to override how the initial value is obtained. This provides reusability through the Open-Closed Principle.
|
|
| Nov 12, 2013 at 20:12 | history | answered | Karl Bielefeldt | CC BY-SA 3.0 |