Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Object coupling and reuse
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
00381906
Message ID:
00381945
Vues:
18
>Is there any rule of thumb when balancing object coupling vs reusing existing objects? In the example below, the device object will return the model name, but it uses the model object to determine this.
>
>By tightly coupling the Device and Model object I am reusing the code to determine a model name, _BUT_ the Device object now relies on the Model object to exist.
>
>Here greatly simplified example:
>
>
>* Dept Class
>DEFINE CLASS Device AS Session
>	PROCEDURE GetModelName
>		PARAMETERS nDeviceId
>                * insert code to get fk_modelid
>                RETURN oModel.GetModelName(fk_modelid)
>	ENDPROC
>ENDDEFINE
>
>* Dept Model
>DEFINE CLASS Model AS Session
>	PROCEDURE GetModelName
>		PARAMETERS nModelId
>                SELECT model
>                SET ORDER TO id
>                SEEK nModelId
>                RETURN model.name
>	ENDPROC
>ENDDEFINE
>
I don't know if there is any rule of thumb but in the above situation I tend to add a property that holds the other object reference for me. Then in the Init() method I would do something like:

THIS.oModel = CreateObject("Model")

In the GetModelName() method I'd call it like:

RETURN THIS.oModel.GetModelName(fk_modelid)

That way if I ever need to change out the oModel object I just change the reference to it in the Init(). You might even want to add another layer of error checking by verifying that VARTYPE(THIS.oModel) = "O" before using it.

If I need to coordinate a couple of different objects (ie. calling a few methods in each from within a method of one of them) I'll break out the functionality into an "event" object. This object strictly creates all the necessary objects then calls the methods in each (along with whatever binding code that is needed).

HTH
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform