Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 4
    Pardon my newness but I’m curious why it wouldn’t be a better approach to make OrderDateInfo HAVE a NamedEntity object as a property? Commented Dec 12, 2018 at 17:33
  • 10
    @AdamB That's a valid design choice. Whether it is better or not depends on what it will be used for among other things. In the exception case, I can't create a new class with an exception property because then the language (C# for me) won't let me throw it. There might be other design considerations that would preclude using composition rather than inheritance. Many times composition is better. It just depends on your system. Commented Dec 12, 2018 at 17:42
  • 17
    @AdamB For the same reason that when you inherit from a base class and DO add methods or properties the base lacks, you don't make a new class and put the base one as a property. There's a difference between a Human BEING a mammal, and HAVING a mammal. Commented Dec 12, 2018 at 17:44
  • 8
    @Logarr true there is a difference between me being a mammal and having a mammal. But if I stay true to my inner mammal you'll never know the difference. You might wonder why I can give so many different kinds of milk on a whim. Commented Dec 12, 2018 at 21:00
  • 5
    @AdamB You can do that, and this is known as composition-over-inheritance. But you would rename NamedEntity for this, e.g. to EntityName, so that the composition makes sense when described. Commented Dec 13, 2018 at 7:45