How to resolve the algorithm Delegates step by step in the Aime programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Delegates step by step in the Aime programming language

Table of Contents

Problem Statement

A delegate is a helper object used by another object. The delegator may send the delegate certain messages, and provide a default implementation when there is no delegate or the delegate does not respond to a message. This pattern is heavily used in Cocoa framework on Mac OS X. See also wp:Delegation pattern. Objects responsibilities: Delegator: Delegate: Show how objects are created and used. First, without a delegate, then with a delegate that does not implement "thing", and last with a delegate that implements "thing".

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Delegates step by step in the Aime programming language

Source code in the aime programming language

text
thing(void)
{
    return "delegate implementation";
}

text
operation(record delegator)
{
    text s;

    if (r_key(delegator, "delegate")) {
        if (r_key(delegator["delegate"], "thing")) {
            s = call(r_query(delegator["delegate"], "thing"));
        } else {
            s = "default implementation";
        }
    } else {
        s = "default implementation";
    }

    return s;
}

integer
main(void)
{
    record delegate, delegator;

    o_text(operation(delegator));
    o_byte('\n');

    r_link(delegator, "delegate", delegate);
    o_text(operation(delegator));
    o_byte('\n');

    r_put(delegate, "thing", thing);
    o_text(operation(delegator));
    o_byte('\n');

    return 0;
}

  

You may also check:How to resolve the algorithm 99 bottles of beer step by step in the 8080 Assembly programming language
You may also check:How to resolve the algorithm Arithmetic/Complex step by step in the smart BASIC programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the langur programming language
You may also check:How to resolve the algorithm Huffman coding step by step in the Go programming language
You may also check:How to resolve the algorithm Pascal matrix generation step by step in the Frink programming language