How to solve the violations of the Law of Demeter?

后端 未结 10 1259
一个人的身影
一个人的身影 2021-01-29 22:23

A colleague and I designed a system for our customer, and in our opinion we created a nice clean design. But I\'m having problems with some coupling we\'ve introduced. I could t

10条回答
  •  佛祖请我去吃肉
    2021-01-29 23:20

    I'd have to assume that the business logic that requires Soluble requires other things too. If so, can some part of it be incapsulated in Medicine in a meaningful way (more meaningful than Medicine.isSoluble())?

    Another possibility (probably an overkill and not complete solution at the same time) would be to present the business rule as object of its own and use double dispatch/Visitor pattern:

    RuleCompilator
    {
      lookAt(Protocol);
      lookAt(Medicine);
      lookAt(AdminstrationProcedure) 
    }
    
    MyComplexRuleCompilator : RuleCompilator
    {
      lookaAt(Protocol)
      lookAt(AdminstrationProcedure)
    }
    
    Medicine
    {
      applyRuleCompilator(RuleCompilator c) {
        c.lookAt(this);
        AdministrationProtocol.applyRuleCompilator(c);
      }
    }
    

提交回复
热议问题