![]() RationalNumber and IntegerNumber show direct inheritance through a generalization association.RealNumber implements the Number class through a realization association.The Number class is an interface and abstract class.This is a small example, but it demonstrates many of the important object-oriented concepts in a single UML diagram: ![]() So, we’ll end up using a composition association between Controller and View, and an aggregation association between Controller and the Number interface. In the code, we see that the Controller class contains an attribute for a single View() instance, and also a list of Number instances. In code, this class would look like this:ĭef sum(self) -> def main(self, args: List) -> None: This is because we don’t want a complex number to contain a complex number, so we’re being careful about our inheritance. Notice that we’re using RealNumber as the attribute instead of the Number interface. So, it will both implement the Number interface, but it will also be composed of two RealNumber attributes. A complex number consists of two parts - a real part and an imaginary part. So, we’ll quickly add those to our UML diagram as well.Īt this point, we can add a new class to representĬomplex numbers. The only way that they differ from the RealNumber class are the attributes. Remember that the arrow itself points toward the interface or parent class.įrom here, it’s pretty easy to see how we can use inheritance to create a RationalNumber class and an IntegerNumber class. So, in our UML diagram, we’ll add another box to represent that class, and use the realization association arrow to show the connection between the classes. It also includes implementations for a couple of other methods beyond the interface, including a constructor. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |