realization and generalization UML?

Viewed 4092

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?

1 Answers

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

Related