Refactoring 012 - Convert Your Key/value Into Full Behavioral Objects
Converting your anemic dictionaries is easy
TL;DR: Convert your key/value into full behavioral objects
Problems Addressed π
- Associative arrays
- Fail Fast principle violation
- Bijection Fault
- Hard to find method references
Context π¬
You have anemic associative arrays that hold unstructured data.
You want richer objects with stricter controls.
Static typed languages can also add type checking to these objects.
Steps π£
- Find the references to the object or associative array
- Reify it
- Replace generic calls with setters and getters for every key.
You can also debug them better this way.
- Add parameter and return type hinting to interfaces.
Do this if your language supports it.
- Add stronger assertions on the setters between different keys.
(if you are using TCR, you can do baby refactoring steps)
Sample Code π»
Before π¨
<?class AuthenticationHelper extends Singleton { private $data = []; function setParameter(string $key, ?$value) { // no type checking...
Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE