Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: ian pano
  Where is ian pano?
 Metro Manila
 Philippines
 ian pano
 Tags
Subject: RE: creating get and set methods for classes
Thread ID: 155190 Message ID: 155201 # Views: 1 # Ratings: 0
Version: Visual FoxPro 9 Category: Classes and Objects
Date: Thursday, December 27, 2007 3:09:00 PM         
   


> dear experts,
>
>
> DEFINE CLASS person as Custom
> 	PROTECTED fname
> 	
> 	PROCEDURE setfName()
> 	LPARAMETERS tcStr
> 		This.Fname = tcStr
> 	ENDPROC
> 	
> 	FUNCTION getfName()
> 		RETURN This.fname 
> 	ENDFUNC
> ENDDEFINE
> 

>
> if i am not mistaken, this is a good practice in OOP, providing an interface for the class users to access or assign a property instead of allowing them to directly manipulate a class' property.
>
> however, is it worth the effort if the class has more than 30 or so properties?
>
>
> tia,
>
> christian pano
> " The bad is entirely my own fault "- Andy Kramek

It might be a good practice w/o a solid standpoint. If I would have public methods to get and set a property w/o any check/alteration etc than I assume I could simply make the property itself public. If I would need a property:
-to be readonly
-to be writeonly
-read returning something different from what is stored (any type of conversion)
-write is writing something different from what the value to be stored is
etc

then I'd explicitly have Access/Assign methods for them (rather than invented method names like setfName/getfName).
If I needed it all for many properies than there is this_access for get part (check its usage in solution samples, some classes use it heavily).

See thread about Access/Assign that were up here recently.

Cetin Basoz

ENTIRE THREAD

creating get and set methods for classes Posted by Christian Pano @ 12/27/2007 7:13:02 AM
RE: creating get and set methods for classes Posted by Vladimir Zhuravlev @ 12/27/2007 7:55:21 AM
RE: creating get and set methods for classes Posted by Boudewijn Lutgerink @ 12/27/2007 9:02:11 AM
RE: creating get and set methods for classes Posted by Cetin Basoz @ 12/27/2007 3:09:00 PM
RE: creating get and set methods for classes Posted by Ken Murphy @ 12/27/2007 4:03:24 PM