Not sure when to use an abstract property and when not

后端 未结 5 1139
野性不改
野性不改 2020-12-04 12:52

I\'m not really sure what looks better or when do I really use in abstract classes and properties, or when to use non abstract properties. I\'ll try to make a simple example

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 13:56

    I know what I want them to do, I don't care how they do it: Interface.

    I know what I want them to do, I don't care how they do some of it, but I've firm ideas on how they'll (or at least most of them) do other bits: Abstract class.

    I know what I want them to do, and how most of them will do it: Concrete class with virtual members.

    You can have other cases such as e.g. an abstract class with no abstract members (you can't have an instance of one, but what functionality it offers, it offers completely), but they're rarer and normally come about because a particular hierarchy offers itself cleanly and blatantly to a given problem.

    (Incidentally, I wouldn't think of a Peter as a type of Human, but of each peter as an instance of human who happens to be called Peter. It's not really fair to pick on example code in this way, but when you're thinking about this sort of issue it's more pertinent than usual).

提交回复
热议问题