Daniel Høyer Jacobsen

INTEGU-java-best-practices-10-guidelines-of-equals

Methods Common to All Objects

Follow The Guidelines Of The Equals-Method
The equals-method need to obey the following four rules to remain functional.

Reflexive: x.equals(x) = true

Symmertric: x.equals(y) = y.equals(x)

Transitive: x.equals(y) = y.equals(z) = true -> z.equals(x) = true

Consistent: x.equals(y) remains the same as long as x and y does not change.

How to write a good equals method:

(Regardless of most IDEs autogenerating them)

First use == to check if the object is equivilent to “this”.
Use instanceof to check if the object is the correct class instance. Otherwise return false.
Cast the object to the same instance as “this”
Check with == if all relevant fields of the class match each other.

composite-design-pattern-overview-INTEGU

Composite Pattern

The composite design pattern is intended for structuring data classes with a relationship to each other. It categorizes the data as either a composite- or and leaf class, which determines whether other classes can be stored within the class. For this reason, it should come as no shock that it is a structural design pattern.

INTEGU - builder-design-pattern-overview

Builder Pattern

The Builder Pattern helps separating the construction of complex objects from the context where they are needed. Additionally, the pattern also contains different variations of objects which have a common construction procedure.

This makes the builder pattern convenient to use when complex objects needs to be created and well aligned with the Single Responsibility Principle. (SRP)

Given that the builder pattern sets up a method for constructing new objects, it is understandably categorized as a creational design pattern.

Scroll to Top
INTEGU - Cookie-consent

INTEGU uses cookies to personalize your experience and provide traceability for affiliate links. By using the website, you agree to these terms and conditions. To learn more see the privacy policy page.