It this an example of the Single Responsibility Principle?

后端 未结 5 1078
时光说笑
时光说笑 2020-12-28 23:57

I made the following code example to learn how to use a generics method signature.

In order to get a Display() method for both Customer and Employee

5条回答
  •  渐次进展
    2020-12-29 00:15

    A few notes:

    • Generally speaking SRP is all good, as is separation of display formatting from data.
    • Considering display etc. I would rather think in terms of services, i.e. a PersonDisplayer is single, stateless and offers a string Display(IPerson) function. IMHO, a special class wrapper just to provide display does not provide any advantage.
    • However, if you used data binding for wpf, you might have a DisplayablePerson class that would propagate PropertyChanged if Person changed. You would put DisplayablePerson objects into ObservableCollection and serve it as ItemsSource of some list control.
    • What do you need Container for, is it only for instantiating and configuring instance?Try then Customer customer1 = new Customer{FirstName= "Jim", LastName= "Smith"};

    • On a side note, I've tried object.Method < SomeType>(...) invocation a few times, as it seemed quickest and simplest solution. However, after some time I've always run into troubles with that one and ended up with object.Method(Type someTypeType, ...)

提交回复
热议问题