Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the java Dimitt principle?

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report