onebip-tip-of-the-month

Using Builder Pattern Implementation to generate value objects

Yesterday while working on a task about the Onebip Core I found a domain concept which was not represented by any object, so I decided to create a new class definition to encapsulate this concept with its own responsibility.

While developing the class I saw that it was not able to know all its attributes without relying on an external source of knowledge. At this early stage of the developing process I decided to pass this external source in the constructor and finish to write my class.

[gist id=5245188]

As you can see an instance of this class is not able to live without the dependency to the external resource, but after a little analysis I saw that all the information I had to retrieve from the external resource could be retrieved when the instance was created.

In the refactoring phase I decided to implement the Builder Pattern, so I have written a DeviceBuilder class which is created with a dependency to the external resource. Once I have the DeviceBuilder I can “set up” the basic information of the device to build and all the  information retrieval is done by the builder before creating the instance of the Device class.

[gist id=5245326]

So at the end of the refactoring we have a value object (the class Device) which is completely isolated from the external source of knowledge. It has no dependency and only represents the domain concept of device.

The dependency is encapsulated within the DeviceBuilder and can be changed any time without having to impact a domain object like the Device.

–By Mirko Bonadei, Onebip Tech Team

Pokud se s výsledkem testu chcete pochlubit, můžete na svůj web lékárně v Praze umístit odkaz na výsledek tohoto testu. Vlastnilekarna kontraindikace dalacin c je kontraindikován u pacientů se známou přecitlivělostí na klindamycin nebo na linkomycin tady nebo na kteroukoli jinou složku přípravku.