1. OO Eu - Where are Member Variables
- Posted by Dave Probert <zingo at purpletiger.com> Dec 16, 2004
- 463 views
Ok, now I'm confused. I've got the 2.5 installation working fine, and the OO version seems to work with the class.ex axample, but I'm kinda lost on the documentation! There seems to be no ability to add Member variables to the euclass - only Methods. This is not very useful as a class needs to have both - encapsulated data and the functions that work with said data. All the examples I've seen just have a few methods which are called, but no examples of using an internal member variable. I attempted to do the obvious like below:
euclass person (integer dummy) -- members sequence firstname, lastname integer age, shoesize atom gender -- methods procedure setName(sequence fname, sequence lname) this.firstname = fname this.lastname = lname end procedure function getFullName() return this.firstname & " " & this.lastname end function function getAgeInDays() return this.age * 365 end function end euclass person jim jim.setName("Jimmy","Brown") puts(1, "Hello " & jim.getFullName() )
But I just get an error when trying to run: Syntax error - expected to see possibly '(', not '=' this.firstname = fname ^ Fatal run-time error: divide by 0 After even more attempts I got to the point where I had no member variables and needed to assign a value to the instance of the class (jim = 6) What is the purpose of giving a class (which is a structure of information) a single value?? Or am I missing something completely? There really needs to be a lot of small examples available of how all this is supposed to work - 'Cos it ain't obvious even to a seasoned programmer like me. I really want to see this become a de-facto standard for OO, so it's gonna need more support. Well, time to get back to the beer, cheers. . .. : :: = == == = :: : .. . Server-Side DB driven web sites, Software Development and part-time games developer contact dave_p at purpletiger dot com . .. : :: = == == = :: : .. .
2. Re: OO Eu - Where are Member Variables
- Posted by Matt Lewis <matthewwalkerlewis at yahoo.com> Dec 16, 2004
- 449 views
Dave Probert wrote: > > Ok, now I'm confused. > > I've got the 2.5 installation working fine, and the OO version seems to work > with the > class.ex axample, but I'm kinda lost on the documentation! > > There seems to be no ability to add Member variables to the euclass - only > Methods. > This is not very useful as a class needs to have both - encapsulated data and > the > functions that work with said data. All the examples I've seen just have a > few methods > which are called, but no examples of using an internal member variable. > <snip> > > After even more attempts I got to the point where I had no member variables > and needed > to assign a value to the instance of the class (jim = 6) What is the purpose > of giving > a class (which is a structure of information) a single value?? Or am I > missing something > completely? > There really needs to be a lot of small examples available of how all this is > supposed > to work - 'Cos it ain't obvious even to a seasoned programmer like me. > > I really want to see this become a de-facto standard for OO, so it's gonna > need more > support. Correct, there is no such thing as member variables. My examples are pretty simple. If you want to have lots of member data, then you should write the class as a sequence, and store the members there. In the future, I may add an ability to use dot notation to refer to members of the sequence. All the data has to be in that variable, because all methods need to have access to it. If I don't put everything together, then I'm going to need to add not just the 'this' param, but all of the member info, as well. I have a specific use where a class would be an atom: when using things like COM or wxEuphoria. The objects are really managed elsewhere, and I just have a pointer to them. Matt Lewis