It this an example of the Single Responsibility Principle?

后端 未结 5 1021
时光说笑
时光说笑 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:29

    Well, I've never heard of this 'single responsibility principle' before, but what it appears to me that what you're doing by having these CustomerPrinter class and CustomerSaver classes is simply converting classes back to structs, and de-object-orienting everything.

    For example, this would mean that different customer types would need different cases in the CustomerPrinter class if they needed to be printed differently. But as I understand it, one of the point of OO organisation, and of using inheritance trees and all that, is to do away with the need of this CustomerPrinter to know how to print everything: Customers know how to print themselves.

    I don't believe in following these paradigms rigidly in any case. For example I'm unsure what the difference between an Interface and an Abstract Class is in your case. But then again I'm a C++ programmer not a C# programmer...

提交回复
热议问题