The VB.NET 'With' Statement - embrace or avoid?

后端 未结 10 2477
感动是毒
感动是毒 2020-11-29 02:53

At work, I\'m frequently working on projects where numerous properties of certain objects have to be set during their construction or early during their lifetime. For the sa

10条回答
  •  醉酒成梦
    2020-11-29 03:20

    I would be suspicious of code that uses a lot this keyword: if it is used to make easier to set lots of instance variables or properties I think this may indicate that your classes are too large ( Large Class smell ). If you use it to replace long chains of calls like this:

    UserHandler.GetUser.First.User.FirstName="Stefan"
    UserHandler.GetUser.First.User.LastName="Karlsson"
    UserHandler.GetUser.First.User.Age="39"
    UserHandler.GetUser.First.User.Sex="Male"
    UserHandler.GetUser.First.User.Occupation="Programmer"
    UserHandler.GetUser.First.User.UserID="0"
    

    then you are probably violating Demeter Law

提交回复
热议问题