Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old June 20th, 2008, 05:40 PM
snoopysalive
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to build Objects containing itself?

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, Statetransitions = 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.CMaps
(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

Reply With Quote
Reply

Viewing: Web Development Archives FAQs Programming > How to build Objects containing itself?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT