1

This is a BON Diagram on the classes.

Notice how in the example, the attributes were not created into instances. At run time a uses take_off from b. I'm just wondering how take_off is being initialized in the B_747 class. In my assignment, I have a case where it's like b := a.b c := a.c where B_747 b and c each has the same attributes, but different value assigned to each. I don't know how to initialize the attributes without them being instantiated. It says I'm not allowed to use b.make ("abc", 123).Can someone give me an example on how to implement this. Also, I'm not really sure what b:=a.b really means.

J0natthaaann
  • 555
  • 1
  • 6
  • 11
  • I would ask your teacher what he means by not creating an instance? Unless an instance is created, your code won't work properly. There is only one way you can initialize an instance is by calling the creation procedure `create x.make (args)`. Otherwise if the type is expanded, then the instance is automatically initialized using `default_create`. – Emmanuel Stapf Feb 19 '14 at 05:31
  • In the above slides, the fact that you do not see the initialization of `a` and `b` is mostly because this is not the point of the slides as it is a slide about polymorphism and dynamic binding. – Emmanuel Stapf Feb 19 '14 at 05:36
  • @J0natthaaann, the description provided seems to be your reinterpretation of the assignment. Posting the original text and asking about the parts that are not clear would be much better both for you to learn and for others to answer. In particular most probably the assignment is not about attribute initialization but about their properties at compile time and at run time. – Alexander Kogtenkov Feb 19 '14 at 06:13

1 Answers1

0

The example illustrates something else, not object creation. Answering your first point, take_off need not be initialized. It is just a feature of class PLANE that is effected in B_747. The slide says that even though the static type of a is PLANE where take_off is declared as deferred (i.e. without any specific implementation), when the variable is attached an object of type B_747, it uses the feature implementation from B_747.

Answering you last point, b := a.b means that a result of a feature b, called on an object computed by an expression a, is attached to a variable b. The latter may be a local variable or an attribute of the current class. Expression a may be a function of the current class, an attribute of the current class, an argument of the current feature, a local variable of the current feature, etc. depending on the context. The feature b called on a may be a function of the class corresponding to the type of a or an attribute of that class.

Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35