What is the difference between generalization and inheritance
In case of Object Oriented Programming, generalization is like to sum up or rather bundle up several functions or methods to a single type or group. If you have declared a parent class and wrote some functions or methods in that class its accessable in that class. Now you make another class and you make it a child class of the previously written class. Now the later written class is a child of the previous class.
Now the later written class can directly use the functions or methods written in the 1st one without being written again in the 2nd class. Difference between Generalization and Inheritance. In this, I frequently come across these two terms: Generalization and Inheritance. But, the difference between the 2 is not clearly mentioned anywhere. Can anybody solve this query? Please provide an example for the same. You can say that fruit is a generalized class of mango. Where all the mango properties defined a fruit.
Do not nest subclass too deeply. Deeply nested subclasses can be difficult to understand. Generalization also lets you adjust the code, where necessary, to get the precise desired behavior. Generalization and specialization concern a relationship among classes and take opposite perspectives, viewed from the superclass or from the subclasses.
Generalization derives from the fact that the superclass generalizes the subclasses Specialization refers to the fact that the subclasses refine or specialize the superclass. The overriding feature the subclass feature refines and replaces the overridden feature the superclass feature You may override a feature: to specify behavior that depends on the subclass, to tighten the specification of a feature, or to improve performance.
For example, in graphic figures class model, each leaf subclass must implement display, even though Figure defines it. Class Circle improves performance by overriding operation rotate to be a null operation You may override methods and default values of attributes. You should never override the signature, or form, of a feature.
You should never override a feature so that it is inconsistent with the original inherited feature. A subclass is a special case of its superclass and should be compatible with it in every respect.
Understand the problem to be solve, the content of model is driven by relevance to the solution. Exercise judgment in deciding which objects to show and which objects to ignore. A model represents only the relevant aspects of a problem. Simplicity: Keep your models simple. Try to use a minimal number of classes that are clearly defined and not redundant. Diagram Layout: Draw your diagrams in a manner that elicits symmetry.
Try to position important classes so that they are visually prominent on a diagram. Try to avoid crossing lines. Names: choose names carefully. Names should be descriptive, and unambiguous. You should use singular nouns for the names of classes References: Do not bury objects references inside objects as attributes. Instead, model these as associations. Multiplicity: Challenge associations ends with a multiplicity of one. For modeling classes that illustrate technical concepts they are secondary.
The reason for this is that modeling relevant objects or ideas from the real world gives little opportunity for using inheritance compare the class diagram of our case study. Nevertheless, we would like to further introduce these terms at this point in Figure 4. 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. In Figure 4. From a domain perspective, the two classes are also very similar. During generalization, the shared characteristics 3 are combined and used to create a new superclass Freight 4.
0コメント