RESEND classes and subclass syntax question

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

RESEND classes and subclass syntax question

mail
Somehow the body of my previous post got stripped out. So I am resending
AGAIN. I changed the formatting from rich text to plain text...


anyone?

lasso 8.6 mac

My goal is to create a set of custom types in which there is a primary
class with several subclasses. I am hoping then that I can define an
instance of that primary class with a set of instance variables, and
then be able to manipulate those with the subclasses... AND to have each
subclass refer to the SAME instance of the Parent class.

First a question about syntax. If I want to make inherited classes that
have a common parent class, do I define them independently, one after
the next, i.e.:

/* *** order object *** */
define_type('order');

    ...
       
/define_type;
   
/* *** service object *** */
define_type('service','order');
   
    ...        

/define_type;

/* *** Product object *** */
define_type('product','order');

    ...

/define_type;

OR, do I nest the sub-objects within the main object:
   
/* *** order object *** */
define_type('order');

    local('a'='')

        /* *** service object *** */
        define_type('service','order');
           
            local('a'='')
            ...        
   
        /define_type;
       
        /* *** Product object *** */
        define_type('product','order');
       
            local('a'='')
            ...
   
        /define_type;
       
/define_type;
       

Next, if I want an instance variable to be manipulated by the
subclasses, how to create and refer to a common instance of the primary
class:

/* *** order object *** */
define_type('order');

    Local(
        'orderTotalCents'=0,
    );
       
/define_type;
   
/* *** service object *** */
define_type('service','order');
   
    ...        
           
    define_tag('addtoOrderAmount',-required='addme');
        self->parent->'orderTotalCents' += integer(#addme);
    /define_tag;

/define_type;

/* *** Product object *** */
define_type('product','order');

    ...
           
    define_tag('addtoOrderAmount',-required='addme');
        self->parent->'orderTotalCents' += integer(#addme);
    /define_tag;

/define_type;

var(
    'PG_orderObj'=order
);
var(
    'PG_subObj'=subscription($GLB_subMap),
    'PG_productObj'=product($GLB_productMap),
    'PG_RP_Obj'=recurPayment($GLB_RP_Map)
);

The problem I have is that each time I instantiate a subclass, it
creates a NEW instance of the primary class, thus the parent references
are each to a different instance of the primary class. Is there a way to
have each inherited class refer to the SAME instance of the primary
class.

$PG_subObj->addtoOrderAmount(100);

Does not add 100 to the primary class (instance variable 'PG_orderObj').
Any help?

I thought maybe I can do this, but does not work:

var(
    'PG_subObj'=$PG_orderObj->subscription($GLB_subMap),
    'PG_productObj'=$PG_orderObj->product($GLB_productMap),
    'PG_RP_Obj'=$PG_orderObj->recurPayment($GLB_RP_Map)
);

Also, if I put parameters to the oncreate in the primary class, lasso is
looking for the same parameters for each of the subclasses (I understand
that since its instantiating a new instance of the "order" class for
each of the subclasses).

Michael

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: RESEND classes and subclass syntax question

Ke Carlton-3
There's a lot of confusion happening here — if a product is not a varient
of an order then why would you want to sub-class an order? It's a
completely different thing. So in this situation you would not sub-class an
order.

In your second approach you've created nested classes — classes that only
exist within that another class (essentially a form of namespacing). I
would not recommend this as it's difficult to work with and not supported
by Lasso 9. A far better approach is to simply namespace your classes (ie.
order_item vs just item).

Also, the use of addtoOrderAmount here is violating a number of
encapsulation principals — essentially the order should be the only class
containing this method. A better approach would be something like:

order->additem(order_item)
order->additem(service)
order->additem(product)

Service and product would be a sub-class of order_item and would contain a
public amount method. Order additem would then call something like
self->addtoOrderAmount(#item->amount)
within the additem method...

Finally, if you want a perpetual instance of an object then use a stub
method:

define_tag('current_order');
   return( var('_current_order') || $_current_order := order(...) );
/define_tag;

Ke


On 22 November 2011 11:41, <[hidden email]> wrote:

> Somehow the body of my previous post got stripped out. So I am resending
> AGAIN. I changed the formatting from rich text to plain text...
>
>
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: RESEND classes and subclass syntax question

Tim Taplin
In reply to this post by mail
It looks to me as if you need to define an item object from which your service and product objects can inherit common methods, then your order object may contain and manipulate your various item objects (products, services, etc) in its structure and can use those object's methods to retrieve and update appropriate values internally.

Your item object, for example, may have a property of item_value, inherited thru to the product object.

/* parent item object */
define_type('item');
        local('item_value' = 0)

/define_type;

> /* *** service object *** */
> define_type('service','item');
>
>    ...        
>
> /define_type;
>
> /* *** Product object *** */
> define_type('product','item');
>
>    ...
>
> /define_type;

your order may for example contain an addItem method and an array of order items, then use the item_value property of your items to calculate a total value, while still being able to inspect the items to see which type they are for further detailed sub summaries.

> /* *** order object *** */
> define_type('order');
>
        local('order_items' = array());
        local('order_total' = 0);

        define_tag('addItem', -required='newitem');
                self->'order_items'->insert(#newitem);
        /define_tag;
       
        define_tag('calcTotal');
                iterate(self->'order_items', local('item'));
                        self->'order_total' += #item->'item_value';
                /iterate;
        /define_tag;
>    ...
>
> /define_type;

Now, I would be inclined to create the item object with properties which defined whether it was a product or service, unless there were a significant number of differences in the functions that each item subtype would carry around.

I believe the key takeaway from this discussion should be that a custom type can contain other custom type objects and utilize their internal methods and properties. Inheritance applies to similar object types which share common properties and methods, not for parent child relationships in a structural or document sense.

Hope that's more helpful than confusing.

Tim Taplin

On Nov 22, 2011, at 4:41 AM, <[hidden email]> <[hidden email]> wrote:

> Somehow the body of my previous post got stripped out. So I am resending
> AGAIN. I changed the formatting from rich text to plain text...
>
>
> anyone?
>
> lasso 8.6 mac
>
> My goal is to create a set of custom types in which there is a primary
> class with several subclasses. I am hoping then that I can define an
> instance of that primary class with a set of instance variables, and
> then be able to manipulate those with the subclasses... AND to have each
> subclass refer to the SAME instance of the Parent class.
>
> First a question about syntax. If I want to make inherited classes that
> have a common parent class, do I define them independently, one after
> the next, i.e.:
>
> /* *** order object *** */
> define_type('order');
>
>    ...
>
> /define_type;
>
> /* *** service object *** */
> define_type('service','order');
>
>    ...        
>
> /define_type;
>
> /* *** Product object *** */
> define_type('product','order');
>
>    ...
>
> /define_type;
>
> OR, do I nest the sub-objects within the main object:
>
> /* *** order object *** */
> define_type('order');
>
>    local('a'='')
>
>        /* *** service object *** */
>        define_type('service','order');
>
>            local('a'='')
>            ...        
>
>        /define_type;
>
>        /* *** Product object *** */
>        define_type('product','order');
>
>            local('a'='')
>            ...
>
>        /define_type;
>
> /define_type;
>
>
> Next, if I want an instance variable to be manipulated by the
> subclasses, how to create and refer to a common instance of the primary
> class:
>
> /* *** order object *** */
> define_type('order');
>
>    Local(
>        'orderTotalCents'=0,
>    );
>
> /define_type;
>
> /* *** service object *** */
> define_type('service','order');
>
>    ...        
>
>    define_tag('addtoOrderAmount',-required='addme');
>        self->parent->'orderTotalCents' += integer(#addme);
>    /define_tag;
>
> /define_type;
>
> /* *** Product object *** */
> define_type('product','order');
>
>    ...
>
>    define_tag('addtoOrderAmount',-required='addme');
>        self->parent->'orderTotalCents' += integer(#addme);
>    /define_tag;
>
> /define_type;
>
> var(
>    'PG_orderObj'=order
> );
> var(
>    'PG_subObj'=subscription($GLB_subMap),
>    'PG_productObj'=product($GLB_productMap),
>    'PG_RP_Obj'=recurPayment($GLB_RP_Map)
> );
>
> The problem I have is that each time I instantiate a subclass, it
> creates a NEW instance of the primary class, thus the parent references
> are each to a different instance of the primary class. Is there a way to
> have each inherited class refer to the SAME instance of the primary
> class.
>
> $PG_subObj->addtoOrderAmount(100);
>
> Does not add 100 to the primary class (instance variable 'PG_orderObj').
> Any help?
>
> I thought maybe I can do this, but does not work:
>
> var(
>    'PG_subObj'=$PG_orderObj->subscription($GLB_subMap),
>    'PG_productObj'=$PG_orderObj->product($GLB_productMap),
>    'PG_RP_Obj'=$PG_orderObj->recurPayment($GLB_RP_Map)
> );
>
> Also, if I put parameters to the oncreate in the primary class, lasso is
> looking for the same parameters for each of the subclasses (I understand
> that since its instantiating a new instance of the "order" class for
> each of the subclasses).
>
> Michael
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: RESEND classes and subclass syntax question

Israel Thompson
In reply to this post by mail
As far as I've ever known, the list ONLY accepts plain text emails. I'm curious how your original even made it through.

Izz


On Nov 22, 2011, at 5:41 AM, <[hidden email]> wrote:

> Somehow the body of my previous post got stripped out. So I am resending
> AGAIN. I changed the formatting from rich text to plain text...
>
>
> anyone?
>
> lasso 8.6 mac
>
> My goal is to create a set of custom types in which there is a primary
> class with several subclasses. I am hoping then that I can define an
> instance of that primary class with a set of instance variables, and
> then be able to manipulate those with the subclasses... AND to have each
> subclass refer to the SAME instance of the Parent class.
>
> First a question about syntax. If I want to make inherited classes that
> have a common parent class, do I define them independently, one after
> the next, i.e.:
>
> /* *** order object *** */
> define_type('order');
>
>    ...
>
> /define_type;
>
> /* *** service object *** */
> define_type('service','order');
>
>    ...        
>
> /define_type;
>
> /* *** Product object *** */
> define_type('product','order');
>
>    ...
>
> /define_type;
>
> OR, do I nest the sub-objects within the main object:
>
> /* *** order object *** */
> define_type('order');
>
>    local('a'='')
>
>        /* *** service object *** */
>        define_type('service','order');
>
>            local('a'='')
>            ...        
>
>        /define_type;
>
>        /* *** Product object *** */
>        define_type('product','order');
>
>            local('a'='')
>            ...
>
>        /define_type;
>
> /define_type;
>
>
> Next, if I want an instance variable to be manipulated by the
> subclasses, how to create and refer to a common instance of the primary
> class:
>
> /* *** order object *** */
> define_type('order');
>
>    Local(
>        'orderTotalCents'=0,
>    );
>
> /define_type;
>
> /* *** service object *** */
> define_type('service','order');
>
>    ...        
>
>    define_tag('addtoOrderAmount',-required='addme');
>        self->parent->'orderTotalCents' += integer(#addme);
>    /define_tag;
>
> /define_type;
>
> /* *** Product object *** */
> define_type('product','order');
>
>    ...
>
>    define_tag('addtoOrderAmount',-required='addme');
>        self->parent->'orderTotalCents' += integer(#addme);
>    /define_tag;
>
> /define_type;
>
> var(
>    'PG_orderObj'=order
> );
> var(
>    'PG_subObj'=subscription($GLB_subMap),
>    'PG_productObj'=product($GLB_productMap),
>    'PG_RP_Obj'=recurPayment($GLB_RP_Map)
> );
>
> The problem I have is that each time I instantiate a subclass, it
> creates a NEW instance of the primary class, thus the parent references
> are each to a different instance of the primary class. Is there a way to
> have each inherited class refer to the SAME instance of the primary
> class.
>
> $PG_subObj->addtoOrderAmount(100);
>
> Does not add 100 to the primary class (instance variable 'PG_orderObj').
> Any help?
>
> I thought maybe I can do this, but does not work:
>
> var(
>    'PG_subObj'=$PG_orderObj->subscription($GLB_subMap),
>    'PG_productObj'=$PG_orderObj->product($GLB_productMap),
>    'PG_RP_Obj'=$PG_orderObj->recurPayment($GLB_RP_Map)
> );
>
> Also, if I put parameters to the oncreate in the primary class, lasso is
> looking for the same parameters for each of the subclasses (I understand
> that since its instantiating a new instance of the "order" class for
> each of the subclasses).
>
> Michael
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: RESEND classes and subclass syntax question

Jonathan Guthrie-3
That's true, however there is a setting in Mailman I turned on months ago that uses a plain text alt if included. My guess is whatever mail client you're using Michael is signalling there's a plain text option but not including it correctly like other clients do.

On 2011-11-22, at 9:56 AM, Israel Thompson wrote:

> As far as I've ever known, the list ONLY accepts plain text emails. I'm curious how your original even made it through.

Jono

----------------------------
Jonathan Guthrie
[hidden email]
LassoSoft Inc.

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>