Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Object vrs Classes

blaze Spinnaker
1/2 Serious
Join date: 12 Aug 2004
Posts: 5,898
09-04-2004 06:35
I get that LSL is object oriented (literally, rather than figuratively) .. but can scripts be classes?

As far as I can tell I can't have a seperate memory space per object without having a seperate script space.

IE: everytime I change the script, I need copy it over to all the other objects if they have their own memory space.

Can you not get class behavior with LSL? Or did I miss something..
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
09-04-2004 08:50
blaze,

Yes, modules are very roughly analagous to objects.

That said, there is a ton of difference between a module-as-object and a class, or even a normal standard programming object.

Note that a class is different from an object. A class is like the mould for a car: it describes how to make a car. An object is an actual real created thing, something like a car itself.

An object offers encapsulation: it hides implementation details from users of the object. A module does that.

An object offers public methods (and often properties) that a user of the object can call. A module does do that, via LinkMessages, but its really a pain in the butt to use since the calls are only asynchronous. Whether technically this counts as public method calls is debatable but its certainly the only "oop" system I've ever seen with async calls...

Classes offer inheritance. In SL, well I guess you can call a script in your inventory a class to the extent that you can rez tons of them. Inheritance would imply that you could take a script you had already written (a "class";) and extend it: add new methods. Arguably you can sortof simulate this with LinkMethods but again its kindof dubious.

As a summary, yeah you can use a script as an object, just as you can use a C module as an object. It's even more similar to a real object than a C module, since you can rez it multiple times without having conflicts in global module variables. You can probably simulate inheritance with LinkMethod passthrus and so on, but on the whole the async nature of "method" calls limits the useability by at least an order of magnitude (in terms of ease of use and speed of implementation).

To get even a chance of pretending to have OOP, we'd really need:
- includes (well, not sure if they really change the nature of OOP, but would certainly make our life easier, reduce configuration control nightmares)
- more script memory (includes are useless if your script stackheaps)
- synchronous method calls to other scripts

Azelda
_____________________
blaze Spinnaker
1/2 Serious
Join date: 12 Aug 2004
Posts: 5,898
09-04-2004 18:04
Having a BSc and 20 years of development experience, I think I get OOP. ;)

Classes don't strictly need inheritance to be considered OOP. In fact, in some ways LSL is more OOP than C++ or Java.

After all, you are forced to use message passing and everything really is objects.

The question was really can an object have a 'mould' as you put it with seperate memory spaces. As far as I can tell that is not possible.
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
09-05-2004 02:03
I think his question was is it possible to have one script working on many sl objects. Right now there is no way to manage scripts as a class. But I believe ll mentioned some sort of plan to implement it in later builds of sl. In-fact I think it was listed as part of the next major update.

I don't if it meet the text book definition of a class. But you'll be able to write one script, and have it egoists on many inventory at ones.


as for the discussion at hand.
I think people can apply, and do apply, the term object oriented programing to almost any and all programing and scripting lounges. Because they they consider encapsulation to count as object oriented programing.

When I think of an object oriented programing in abstract-action there is allot sls cannot do. Because it fails to support some basic data, and data structures. Like classes, over loading, operators, includes. This interferes with abstraction encapsulation and information hiding.
Tcoz Bach
Tyrell Victim
Join date: 10 Dec 2002
Posts: 973
09-07-2004 16:45
No. You can not create instances of user defined types in LSL.

Objects with LSL on them are more analagous to components than classes. Think old Flash/Actionscript movie clips.

A shame all the OOP chatter from the old forums was lost.
_____________________
** ...you want to do WHAT with that cube? **