syntax on a class

syntax on a class

Postby Silvio.Falconi » Wed Apr 27, 2016 2:43 pm

I with create a method if I have a logic value .t.

METHOD SetUpperCaps(lUpp) INLINE if(lUpp, ::func1(),::func2())


or
how I must make it ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7042
Joined: Thu Oct 18, 2012 7:17 pm

Re: syntax on a class

Postby James Bott » Wed Apr 27, 2016 5:47 pm

Silvio,

Normally you would do something like this:

Code: Select all  Expand view
Method SetUpper( lUpper )
   if lUpper != nil
      ::lUpper:= lUpper
   endif
return ::lUpper

Method Whatever( cString )
   if ::lUpper
       cString:= upper( cString )
   endif
return cString
 


Note that you could just access ::lUpper directly like oObj:lUpper:=.t. without the setUpper() method, but OOP principles state that no DATA should be accessed directly, but rather should be set using a method. This does prevent data from being changed that may depend on other settings (DATA) being set a particular way, and visa versa. I think this is a bigger concern when you have multiple programmers working on a project that might not be fully aware of the consequences of changing DATA directly.

However, your definition could work. Did you try it? However, if you need to pass something to either func1() or func2() then they would have to be passed to the setUpper() method which is very confusing. It is better to set the DATA (::lUpper) then use that data in a method that does different things depending on its value (such as my Whatever() method).

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: syntax on a class

Postby Silvio.Falconi » Thu Apr 28, 2016 8:00 am

resolve
xhabour not want !lUpp on comand inline
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7042
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], RSalazarU and 46 guests