问题
I am having a hard time actually finding the difference between a Generalization and a Specialization, and when to use either one.
Can anyone enlighten me?
Eventually also an illustration using UML
回答1:
Animal
is a generalization , Dog
is specialization. Your superclass is a generalized class , but your subclass will be a specialized inheritor of your superclass. It becomes more specialized and less generalized as you move down the inheritance hierarchy .
Generalization
Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass. Shared characteristics can be attributes, associations, or methods.
Specialization
If some new subclasses are created from an existing superclass to do specific job of the superclass, then it is known as specialization.
You can get more clear tutorial with UML diagrams here.
来源:https://stackoverflow.com/questions/17084034/generalization-and-specialization-what-is-the-differences