Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > How to build Ob...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 5767 of 5930
Post > Topic >>

How to build Objects containing itself?

by "snoopysalive@[EMAIL PROTECTED] " <snoopysalive@[EMAIL PROTECTED] > Jun 20, 2008 at 03:06 PM

Hi!

So, here's my next question about object orientation in Ada.

In languages like Ruby, C++ or Java, the following construct is
possible (here in Java):

class State {
    HashMap<char, State> transitions = new HashMap<char, State>();
}

Perhaps you're wondering, what this code is meant to be. Some time ago
I programmed a stack-structure simulating a trie as part of a
incremental search-algorithm. The idea was to have a state-object
containing a mapping of characters pointing to state-objects again.
So, the result is a data-structure containing instances of its own
data type again.

As object orientation is a bit different in Ada, the previous code
example would be something like this in Ada:

package State is

    type State is tagged
        record
            Transitions : Transition_Maps.Map;
        end record;

    package Transition_Maps is new Ada.Containers.Ordered_Maps
        (Key_Type => Character,
         Element_Type => State,
         "<" => "<",
         "=" => "=");
    use Transition_Maps;

end State;


As you can see, we have a "What had been there first? The hen or the
egg?"-problem: The State-record requires an instance of
Transition_Maps.Map which is declared after the State-record's
definition. But because Transition_Maps.Map needs a State as
Element_Type changing the order ends in the same problem.

So, has anybody an idea, how to solve this paradox?

Thanks,
Matthias
 




 3 Posts in Topic:
How to build Objects containing itself?
"snoopysalive@[EMAIL  2008-06-20 15:06:10 
Re: How to build Objects containing itself?
george.priv@[EMAIL PROTEC  2008-06-20 15:42:08 
Re: How to build Objects containing itself?
Ivan Levashew <octagra  2008-06-21 12:57:58 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 22:20:35 CDT 2008.