Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best Application Object example?
Message
De
24/11/1999 22:55:46
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00294399
Message ID:
00295460
Vues:
30
>I went back and forth on this a lot when we were working on the design of our framework. Here are a couple of things to keep in mind:
>
>1. Public variables are generally considered bad practice in OOP, therefore, in theory, the fewer the better.

Right. I don't use any public variables. In my Main.prg I have PRIVATE ThisApp.

>
>2. Having a global application object that provides a wide variety of services does not limit your testing any more than using several different global objects. There's really no difference if your code checks for oApp.oSecurity vs. just oSecurity. In reality, the application object can actually enhance this because if you wanted to you could have objects like oSecurity, oFormMgr, etc. created on demand via access methods.

I don't think the way I'm doing it now (one big application object that has methods to do things like form management, etc.) is wrong...it just isn't as efficient as different objects that do these other things.

>
>3. If you reference a hard coded variable name throughout your application code it will be a lot harder to change down the road later. You might want to consider making these items protected members of your application object and then when you want to interact with one of them, call a method that returns an object reference back. If you take this route all of your access to these objects is handled with one clean interface and if how that object is created changes you only need to change one place. IOW, GetFormManager could be RETURN This.oForms or it could be RETURN oForms if you later decided to move it to a variable. (This also helps to enforce encapsulation.)

That's definately the way I'm thinking now.

>
>4. The GetMethod approach I've described above also provides more flexibility because it can also use on demand instantiation or if the situation dictates it, it can actually make decisions regarding which object is returned. With a public variable object the only time you can really control the class is at instantiation time.

Yup. Reading Jim's and Steve's book has caused me to rethink my approach. This is exactly what I'm looking at doing now. I'm going to read Markus' book before I start rebulding anything.

Thanks for your input
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform