2

I don't understand the difference between the UML realization and generalization arrow in UML class diagrams. In my code specific, I created an interface:

public interface IParser {
   void Parse(string[] txtFile);
   void Add(List<char> gameMap);
}

And I inherit it:

public class ParseExits : IParser {

   public Dictionary<char, string> Dict { get;  }
   public List<Entity> EntityList  { get; }

   public ParseExits() {
            Dict = new Dictionary<char, string>();
            EntityList = new List<Entity>();
        }

   public void Parse(string[] txtFile) {
       ...
   }

   public void Add(List<char> gameMap) {
       ...
   }

I would say it's a realization as I inherit the whole interface. I realize the IParser (the "template"). Whereas a generalization would be to use some of the interface? Is this a correct distinction?

jubibanna
  • 1,095
  • 9
  • 21
  • @momo : You are right. Please copy your comment to an answer. Please use comments to ask for clarification and not to give an answer. – www.admiraalit.nl Jun 17 '19 at 09:20
  • Could you show a simple code-example of when generlization should be used instead of realization? And thank you for the answer! – jubibanna Jun 17 '19 at 09:21

1 Answers1

0

You can say that IParser is realized (implemented) by ParseExits. Generalization is different and occurs when you use inheritance. For example the base class "Animal" and the class that inherits from an animal: "Tiger". In this case, you can call it "is a" relationship. A "Tiger" is an "Animal". A "Tiger" is generalized by "Animal.

Your second question is more of a “general object-oriented” question.

Inheritance vs composition: Generally speaking, it is more robust to use composition instead of inheritance and it is not so easy to get rid of your genes. (google composition over inheritance)

Interface vs (abstract) class: Read this StackOverflow answer

momo
  • 3,313
  • 2
  • 19
  • 37