Computer Science Canada Constructors in Turing |
Author: | uncompetence [ Tue Jun 09, 2009 10:58 pm ] |
Post subject: | Constructors in Turing |
I'm toying with Object-Oriented in Turing and looked through the reference under 'class' and found no means of writing a constructor for an object. All calls to new perform the initialization of the object, but there seems to be no way of passing in variables. Is there no other way than to write and call a method of my own? |
Author: | wtd [ Tue Jun 09, 2009 11:44 pm ] |
Post subject: | RE:Constructors in Turing |
As far as I know, there is no way to have a constructor in the sense that other object-oriented programming languages have. |
Author: | [Gandalf] [ Wed Jun 10, 2009 1:49 am ] |
Post subject: | RE:Constructors in Turing |
Indeed, you are stuck with creating your own initialize() function and always calling that. |
Author: | DemonWasp [ Wed Jun 10, 2009 8:03 am ] |
Post subject: | RE:Constructors in Turing |
Similarly, there's no way to have a proper destructor. |
Author: | Tyr_God_Of_War [ Thu Jun 18, 2009 7:03 pm ] | ||||||
Post subject: | Re: Constructors in Turing | ||||||
I do not think that you can have any class methods (also know as static methods) at all. That's why I think it's better to use a type and a module. You can treat it like python, where you have to list 'self' as a parameter for your methods.
Compare this to a class version.
Or if you really want dynamically allocated stuff:
As you can see, using a module and a type is much like using a class. Modules can have static methods, while classes get inheritence and polymorphism. |