Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Sounds like a fun (and educational) project. A couple of things you may want to look further into:<bl>
  • A common pattern for handling Undo is to have each undoable operation return an object that knows how to undo that operation. These objects carry enough context (perhaps the old value of whatever was changed) that they can be told to undo (but only in order). For more discussion on this, see the discussion of the Command pattern in the book "Design Patterns: Elements of Reusable Object-Oriented Software" or in the many web sites dealing with Design Patterns.
  • One kind of software architecture that has been useful is what is known as a "prototype based" system. This is a kind of object oriented system that does not depend on "classes" for inheriting (reusing) behavior, but rather on maintaining references to objects whose behavior is similar. This works better than traditional class-based inheritance if you have many objects (or characters or other game artifacts in your system) that are almost but not quite the same in their behavior. For instance, a cursed sword of a certain kind might have subtle changes in its damage. Rather than testing this in the code for computing sword damage, you can instead attach the proper code bits for dealing with cursed swords. This is a more flexible and fine-grained way to deal with the many kinds of behavior than a class-based system. Perl's object model is flexible enough to support prototype based programming. To understand how to do this, you first have to understand how Perl's method lookup works for an object: when you call a method on an object like this:
    my $sword = Sword->new("Excalibur"); my $damage = $sword->damage($someOtherPlayer);

    Perl will first look in the Sword package for a subroutine called "damage". Failing this, it will search each of the packages named in the @Sword::ISA list for a subroutine called "damage". If it still doesn't find damage(), then it will call AUTOLOAD with the name of the missing method ("damage") as well as the arguments to that method. How can you do prototype based programming with this? Simple: by exclusively using AUTOLOAD to call whatever functions need to be overridden on a fine-grained basis (that is, anything you didn't define in the package of the object itself or one of the packages named in its class's @ISA array).

    You can do this by maintaining named slots for overridable methods, putting subroutine references into these slots, and then calling them from your AUTOLOAD method.

    Where the "prototype" comes in is that an object could refer to another object whose behavior it can share.

    Of course, being lazy, one could look at CPAN and find the modules Class::SelfMethods or Class::Classless, which provide for a couple of different kinds of prototype-based programming support.

  • </bl>

    Best of luck with this project!

    updated: clarified use of prototype


    In reply to Re: Daft text adventure project by bikeNomad
    in thread Daft text adventure project by Tiefling

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (1)
    As of 2020-12-05 06:37 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How often do you use taint mode?





      Results (63 votes). Check out past polls.

      Notices?