Java

INTEGU-java-best-practices-15-Limit-access-to-class-members

Classes & Interfaces

15. Limit Accessibility To Classes And Members
Generally, any class or member of a class should have the lowest possible access level, which still allows for its functionality to work.

API Example:

Take the case of an externally exposed API, where the interface represents all public accessible methods. Any implementation of this interface should only have public access level on the implemented methods.

The additional members of the implementing class should never be made public. Ideally private or package-private if required for unit testing.

In the case of the exposed API, any publicly available member of the implementation will have to be supported forever, if they have once been published. If members are degraded to a lower access level, it will ruin the API’s backwards compatibility.

INTEGU - Factory-Design-Pattern-Overview

Factory Pattern

As arguably the most popular creational design pattern, the factory pattern provides guidelines for how to flexibly and conveniently create different objects with the same method, by only changing the method’s argument. Utilizing the factory pattern in the creation of objects allows all complexities of the creation to be hidden away. Simultaneously the factory can be designed to create any variation of an object, as long as all objects extend from the same super-class.

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.