Java Programming Principles : Law of Demeter

Hi All,

Today , We will look at once the famous Java programming Principles .

What is The Law of Demeter (LoD) : LOD is a software design principle that was first described by Ian Holland at Northeastern University in 1987. The principle is named after the Greek goddess of the harvest, Demeter, and is also known as the “principle of least knowledge” or the “principle of least coupling”.

The Law of Demeter states that an object should only communicate with its immediate neighbors and should have only limited knowledge of the inner workings of other objects. This helps to reduce the complexity and dependencies of a system, and makes it easier to maintain and modify. The principle is often applied in object-oriented programming languages, such as Java, to help create more modular and maintainable code.

In Java, the Law of Demeter can be applied by limiting the number of method calls that an object makes to other objects and by minimizing the number of classes that an object has direct knowledge of. This can be achieved through techniques such as encapsulation, dependency injection, and the use of interfaces.

--

--

A Passionate Programmer - A Technology Enthusiast

An Architect practicing Architecture, Design,Coding in Java,JEE,Spring,SpringBoot,Microservices,Apis,Reactive,Oracle,Mongo,GCP,AWS,Kafka,PubSub,DevOps,CI-CD,DSA