Question to classes

Question to classes

Postby Otto » Tue Dec 04, 2007 9:14 pm

Question to classes: is it possible/allowed in OOP to use a class own method within the class?
Thanks in advance
Otto
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Question to classes

Postby Enrico Maria Giordano » Tue Dec 04, 2007 10:43 pm

Of course:

Code: Select all  Expand view  RUN
::MethodName( params )


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8716
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby James Bott » Wed Dec 05, 2007 2:29 am

Otto,

That is one of the great features.

You may want to read, or reread, the OOP articles on my website.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Otto » Wed Dec 05, 2007 2:48 am

Thank you Enrico and James,

I made an ‘invoice class’ and an ‘invoice position (record)’ class.
Now to calculate the line total I made a function inside the InvoicePositionclass.
Amount per price – SetText to a oSay.
Here I don’t know what to use a function or a method


METHOD New
oGet nAmount valid calculate() or ::calculate()
oGet nPrice valid calculate() or ::calculate()
oSay nTotal
return Self

func calculate()
return

METHODE calculate
Return nil

What would be the right way to define the variables (nAmount,nPrice): static, local and pass them, DATA?

Hope you will help me on that.
Thanks in advance
Otto
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Postby James Bott » Wed Dec 05, 2007 3:35 am

Otto,

>I made an ‘invoice class’ and an ‘invoice position (record)’ class.
>Now to calculate the line total I made a function inside the >InvoicePositionclass.

Ok, you picked a very complicated class to start with. An invoice is an object that contains other objects. The invoice object contains a customer object, and multiple line item objects (one for each item). So you need at least three classes to create an Invoice object.

>Amount per price – SetText to a oSay.
>Here I don’t know what to use a function or a method

In pure oop you never use functions. However, in our hybrid OOP system you try not to create functions, but you can use all the FW and Harbour functions. So if you need something new, then create a method.

>METHOD New
>oGet nAmount valid calculate() or ::calculate()
>oGet nPrice valid calculate() or ::calculate()
>oSay nTotal
>return Self

I'm not sure what you were trying to do with the above. The New() method should only initialize the object.

Perhaps you should start with a Customer class instead. It would much simpler than an Invoice class. There is discussion of a customer class in my OOP articles.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Otto » Wed Dec 05, 2007 10:48 am

Hello James,

thanks for your answer.
Where did you get all your knowledge from?
I will re-read your articles.
Regards,
Otto
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Postby Enrico Maria Giordano » Wed Dec 05, 2007 11:48 am

There are bunch of books dedicated to the OOP in the libraries and on Internet.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8716
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Wed Dec 05, 2007 1:04 pm

Otto,

In FWH\source\classes\*.prg there are lots of examples :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 57 guests