Is there some literature on this type of programming?

前端 未结 8 820
[愿得一人]
[愿得一人] 2021-02-01 05:56

In college I took on a class on modern physics, in which we learned about special relativity. I was completely blown away by how different frames of reference could actually ob

8条回答
  •  滥情空心
    2021-02-01 06:58

    This design pattern can work well, particularly if the operations do not mutate the original data objects. In .NET, for instance, LINQ and its associated extension methods can be seen as general operations for dealing with enumerations, so that the enumerations themselves do not need to know how they may be used. The methods do not, however, mutate the collections being enumerated, but merely provide a new way to interpret, filter and group the enumeration.

    If the functionality is mutating the original objects, however, then I tend to prefer that functionality to be encapsulated as methods on the object. That way the object is responsible for maintaining its own invariants and you insulate more of the implementation details from the clients of the object. The more implementation detail you must leak in order to work with the object, the more opportunity there is for it to be used incorrectly and cause bugs.

提交回复
热议问题