Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the java Dimitt principle?

Shulou Source: shulou.com Published: 2022-06-01 13:49:26 10月03日 Update

This article introduces the relevant knowledge of "what is the java Dimitt principle". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Dimitt principle (LOD), The Law Of Demeter, also known as least knowledge principle

Define

An object should have the least knowledge of other objects.

In other words, a class should know least about coupling and calling a class, it only cares about the public methods of the class being coupled and called, and it doesn't care how complex the class is. On the other hand, this also shows the minimum weight of class methods, do not define public exposed methods at will, you only expose what you need to expose.

The Demeter principle puts forward the following requirements for the low coupling of classes:

1. Only communicate with friends

The communication between classes does not need to know the internal structure, and I don't care about dealing with other strangers.

2. The distance between friends

The more properties and methods a class exposes, the more likely it is to be modified, so when designing one, it is necessary to weigh the pros and cons and define the scope within a reasonable range.

Therefore, the obvious advantage of Dimit is the low coupling degree, which improves the maintainability and expansibility of the system. But on the other hand, in order to meet these characteristics, we have to add a lot of wrapped classes or methods, which increases the complexity of the class to a certain extent.

This is the end of "what is the java Dimitt principle". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Principles Dimitri methods coupling knowledge complexity between content objects more friends degree coupling scope communication practical obvious minimum unfamiliar weigh pros and cons Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Microsoft Shulou Information Huawei OPPO Reno