Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Referencing a parent's object
Message
De
29/08/2007 15:04:23
Mike Yearwood
Toronto, Ontario, Canada
 
 
À
29/08/2007 14:23:23
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
01250681
Message ID:
01251216
Vues:
16
>>>>>If I were the original designer of Jay's system (unlikely since my design skills are not all that strong), each of the two objects would be properties of the same parent object and you could get the values from This.Parent (Question....in OOP design is an object supposed to know about its parent's methods and properties?).
>>>
>>>I'm curious about this question. How much is an object supposed to know about its parent?
>>
>>Depends what you mean by parent. Containing object? *All* objects are supposed to be designed so they know divulge as little as possible to the outside world, which includes all other objects in the system. At design time we programmers can usually see all of the insides of a given set of modules. At runtime they must not see into each other.
>>
>>subclass can see whatever it is allowed to see of the superclass by the designer.
>>
>Apparantly I haven't phrased the question properly. I don't think I'm talking about sub/super classing. Let me try again.
>DEFINE CLASS firstlevel AS custom
>  myObj1 = .null.
>  myObj2 = .null.
>
>  FUNCTION init
>     this.myObj1 = CREATEOBJECT("something")
>     this.myObj2 = CREATEOBJECT("something else")
>  ENDFUNC
>ENDDEFINE
>
>According to OOP theory.......
>
>1. Should myObj1 know anything about myObj2 so that one of its methods might do something like
>       ** myOjb1.TestConnection
>       IF this.parent.myObj2.getSockState() = "val"
>             etc
>
ALL objects should know as little as possible about each other. Calling an exposed method is ok.

>2. Would this be a valid way to do what Jay was asking about?

Probably.

>3. If the answer to these questions is Yes, why is it better than the functionally equivalent
>
>** Mainlevel.prg
>     myObj1 = CREATEOBJECT("something")
>     myObj2 = CREATEOBJECT("something else")
>
>       ** myOjb1.TestConnection
>       IF myObj2.getSockState() = "val"
>             etc
>
I don't think it's any better. Mainlevel is a component as is firstlevel.

The only point is that myObj1 should not be free to reach into myObj2 and change it's properties WHILE myObj2 is doing things with those properties. It would be like me reaching into your stomach (if that were possible) while you're not aware of it.

A public oApp object with public properties is every bit as susceptible to the objects in the system changing those properties that other parts depend on. That's breaking encapsulation!
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform