|
|
[Ctype Carry Demonstration]Rich Fortnum, November 01, 2005 After studying some OOP through Lasso, I wrote up some test pieces that demonstrate the concepts at work. While there seems to be a bit of a void for such programming topics demonstrated in lasso, I submit this piece to show how instances of ctypes can be carried within the lasso environment. While a custom type can be instantiated and manipulated in a file, by the end of the page, it has to be stored somewhere so that it can be used elsewhere. Hence the assignment to a session variable. This also demonstrates how easy it is to code for changing attributes for a ctype as well as calling attributes in a stored instance. If you design a system where multiple instances are stored in session vars (each with a unique name if contained at the same time), then it demonstrates how much LESS code there would be, as well as the time saver and encapsulation. start.lasso --> one.lasso --> two.lasso --> three.lasso START.LASSO ONE.LASSO TWO.LASSO THREE.LASSO TEST_CTYPE.LASSO
local: 'colour' = string, define_tag: 'setMake', -required = 'newmake';
define_tag: 'setColour', -required = 'newcolour';
START.LASSO
include: 'test_ctype.lasso'; session_start: (session_addvar: -name='ss', 'currentcar'); var: 'currentcar' = car; '...set svar...<br/>'; ?> ONE.LASSO
include: 'test_ctype.lasso'; session_start: ($currentcar->make) ' / ' ($currentcar->colour) ' / ' ($currentcar->speed) ' @ 1/a <br/>'; '...setting colour to red...<br/>';
($currentcar->make) ' / ' ($currentcar->colour) ' / ' ($currentcar->speed) ' @ 1/b <br/>'; ?> TWO.LASSO
include: 'test_ctype.lasso'; session_start: ($currentcar->make) ' / ' ($currentcar->colour) ' / ' ($currentcar->speed) ' @ 2/a <br/>'; '...setting speed to 120...<br/>';
($currentcar->make) ' / ' ($currentcar->colour) ' / ' ($currentcar->speed) ' @ 2/b <br/>'; ?> THREE.LASSO
include: 'test_ctype.lasso'; session_start: ($currentcar->make) ' / ' ($currentcar->colour) ' / ' ($currentcar->speed) ' @ 3/a <br/>'; '...setting make to VW...<br/>';
($currentcar->make) ' / ' ($currentcar->colour) ' / ' ($currentcar->speed) ' @ 3/b <br/>'; ?> |
Articles |