简体   繁体   English

初始化而不创建实例(Eiffel)

[英]initializing Without Creating An Instance (Eiffel)

This is a BON Diagram on the classes. 这是类的BON图。

Notice how in the example, the attributes were not created into instances. 请注意,在示例中,如何将属性未创建到实例中。 At run time a uses take_off from b . 在运行时a使用b take_off I'm just wondering how take_off is being initialized in the B_747 class. 我只是想知道如何take_off在B_747类被初始化。 In my assignment, I have a case where it's like b := ab c := ac where B_747 b and c each has the same attributes, but different value assigned to each. 在我的作业中,我遇到一种情况,就像b := ab c := ac ,其中B_747 bc各自具有相同的属性,但分配给它们的值不同。 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. 它说我不允许使用b.make ("abc", 123) 。有人可以给我一个如何实现此示例的例子。 Also, I'm not really sure what b:=ab really means. 另外,我不确定b:=ab真正含义。

The example illustrates something else, not object creation. 该示例说明了其他内容,而不是对象创建。 Answering your first point, take_off need not be initialized. 在回答您的第一点时,无需初始化take_off It is just a feature of class PLANE that is effected in B_747 . 这只是在B_747生效的PLANE类的功能。 The slide says that even though the static type of a is PLANE where take_off is declared as deferred (ie without any specific implementation), when the variable is attached an object of type B_747 , it uses the feature implementation from B_747 . 滑动说即使静态类型的aPLANE其中take_off为递延被声明(即,没有任何特定的实现),当变量被连接类型的对象B_747 ,它使用从特征实施B_747

Answering you last point, b := ab means that a result of a feature b , called on an object computed by an expression a , is attached to a variable b . 回答您最后一点, b := ab意味着将特征b的结果(由表达式a计算的对象调用)附加到变量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. 根据上下文,表达式a可以是当前类的函数,当前类的属性,当前特征的自变量,当前特征的局部变量等。 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. 特征b称为上a可以是对应于所述类型的类的功能a或该类的一个属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM