Re: Procedural design patterns?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Doing what you want to do in a pseudo-object-oriented fashion in Euphoria really shouldn't be that difficult, the main differences will be that you have to do some manual bookkeeping (keeping track of object instances), you have to manually specify a "this" parameter, and that you can't use dot notation.

  • Create a file for your class. The filename and default namespace is your class name. Many true object-oriented languages require this as well.
  • Create your class variables. You will need to keep your instances either in a simple list, or you could use more complex data structures such as stack, map, whatever. Heck, you could probably even use EDS if you needed to be able to save and restore your state.
  • Create your object data type and any enums or constants required to be used with them.
  • Create your class methods, such as "new", "delete", or any others which work on the class as a whole. These can be procedures or functions as required.
  • Create your instance methods, such as getters and setters and "copy", "clone", comparisons, etc. as required.
    • Instance methods should take at least one parameter corresponding to "this" object -- usually some key returned by the "new" method. This is your key into your object list (whether a simple list or whatever).
    • Some instance methods may take an entire object representation to work on, but this should be avoided if possible.

For inheritance, you just include the parent classes/files in your new class/file. Prototyping is kind of built-in, you can get pretty involved with copying classes, objects, and methods if you need to.

Avoid exposing any variables outside of your class file -- make them all accessible and modifiable by getters/setters and other methods. At the most, a particular method may return an object representation as a sequence or may take an object represented as a sequence as an input parameter, but again that should be relatively rare.

Note: I've never actually done any of this, but Euphoria has the tools built-in to do it.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu