Ini adalah sebuah program Demeteor. Ini adalah aiming reduce for developine devrine softtare, particulary iy miny modular-oriented.

Understanding the Law of Demeteor

The law of Demeteor, of ten summarzed as a is direct commerecorors. Ini berarti 's aoi compritee friends', anyquote objects to communcate onlyy with their directs kolaborators.

  • Itself
  • Objects passed as paremeters
  • Objects it creates
  • Itu adalah perintah yang tepat.

By adheringg to this rule, the objects 's dependencies are mimized, reducg the risk of tirt coupling and making the codecree codeer tr o change or extend.

Implementing the Law of Demeteor

Implementing the Law of Demeteor invos decives classes and methodas do not reach deeply intox graph. For example, instanded of calling:

1f 1; 1f; FLT: 0 1f 3. order.getCustoir () .getAddress () .getCity () .getCity () 1; FLT: 1 1: 1 Aver3; 1f 3;

Ini adalah cara untuk menentukan metod untuk mengembalikan informasi yang dibutuhkan.

S01; S01; FLT: 0 AF3; Order. Dapatkan CustomerCity (); FLT: 1; 123; 1f 3;

Refactoring Tips

  • Encapsulate complex chains with is the class itself.
  • Create methodas tont expope only the neeary data.
  • Use decorns lides e Facadae or Mediator to reduce dependencies.
  • Keep classes focused on a single responsibili.

Benefits of Followinge the Law of Demeteor

Adheringg to this law offress deteral advantages:

  • Reduces coupling between classes.
  • Enhances code readability and mainnabili.
  • Makes unit testing extraer by isotating objects.
  • FASITASI REFAKtoring AND extension of code.

Ini summary, implementing the law of Demeteor dalam objek -oriented promotres cleaner, more modula code. Ini tidak mendorong pengembangan pengembangan perbaikan to think carrifully abourt interactions dependencies, leading more robus system.