How to resolve the algorithm Call an object method step by step in the Quackery programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Call an object method step by step in the Quackery programming language
Table of Contents
Problem Statement
In object-oriented programming a method is a function associated with a particular class or object. In most forms of object oriented implementations methods can be static, associated with the class itself; or instance, associated with an instance of a class. Show how to call a static or class method, and an instance method of a class.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Call an object method step by step in the Quackery programming language
Source code in the quackery programming language
( ---------------- zen object orientation -------------- )
[ immovable
]this[ swap do ]done[ ] is object ( --> )
[ ]'[ ] is method ( --> [ )
[ method
[ dup share
swap put ] ] is localise ( --> [ )
[ method [ release ] ] is delocalise ( --> [ )
( -------------- example: counter methods -------------- )
( to create a counter object, use:
"[ object 0 ] is 'name' ( [ --> )" )
[ method
[ 0 swap replace ] ] is reset-counter ( --> [ )
[ method
[ 1 swap tally ] ] is increment-counter ( --> [ )
[ method [ share ] ] is report-counter ( --> [ )
( -------------------- demonstration ------------------- )
say 'Creating counter object: "mycounter".' cr cr
[ object 0 ] is mycounter ( [ --> )
say "Initial value of mycounter: "
report-counter mycounter echo cr cr
say "Incrementing mycounter three times." cr
3 times [ increment-counter mycounter ]
say "Current value of mycounter: "
report-counter mycounter echo cr cr
say "Localising mycounter." cr cr
localise mycounter
say " Current value of mycounter: "
report-counter mycounter echo cr cr
say " Resetting mycounter." cr
reset-counter mycounter
say " Current value of mycounter: "
report-counter mycounter echo cr cr
say " Incrementing mycounter six times." cr
6 times [ increment-counter mycounter ]
say " Current value of mycounter: "
report-counter mycounter echo cr cr
say "Delocalising mycounter." cr cr
delocalise mycounter
say "Current value of mycounter: "
report-counter mycounter echo cr cr
say "Resetting mycounter." cr
reset-counter mycounter
say "Current value of mycounter: "
report-counter mycounter echo cr cr
You may also check:How to resolve the algorithm String comparison step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Strip a set of characters from a string step by step in the Powershell programming language
You may also check:How to resolve the algorithm Calculating the value of e step by step in the Applesoft BASIC programming language
You may also check:How to resolve the algorithm Find common directory path step by step in the Maple programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the APL programming language