Hi

Just expanding on that last thread, (“Why does this not work") there do appear 
to be some real object orientation aspects to the new 4D commands - at least 
from the point of view of what’s needed and useful in a high level environment 
like 4D.

The key is the new “This” self-referencing function because it now lets you 
create an active object as a class. I realise OO purists may not regard it as a 
class, but it’s as much of a class as I’ve ever used in OOP languages and I 
don’t see what else we’d want or need. It can contain both encapsulated 
properties AND methods. Also, we don’t need to keep passing it an object 
reference from an external call to execute those methods using the “internal” 
properties and we can create new instances of objects from that class using the 
OB Copy command (which basically does the same job as “New”).

Immense !

For example, try this (needs v17 R3 or greater):

C_OBJECT($animal;$dog;$cat;$pet)

// 1. Define a class

$animal:=New object("sound";"";"talk";Formula(ALERT(This.sound)))

// 2. Instantiate new objects from the class which inherit its properties and 
behaviours

$dog:=OB Copy($animal)
$cat:=OB Copy($animal)

// 3. Customise the objects

$dog.sound:="wooff"
$cat.sound:="meow"

// 4. Do stuff using the encapsulated object reference defined in the class

$pet:=$dog
$pet.talk()

$pet:=$cat
$pet.talk()

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to