From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: What is your opinion on Global Objects? Date: Tue, 18 Nov 2014 20:03:27 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Wed, 19 Nov 2014 03:03:17 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="e1e8835fd7030ec2a5463beff662d0eb"; logging-data="21567"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PftbkeeTkHUb68ExLTgU5QYqoWLG7Yyc=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: Cancel-Lock: sha1:bJ1JDBVTnOgATfyJ3pl6UgGhICI= Xref: news.eternal-september.org comp.lang.ada:23539 Date: 2014-11-18T20:03:27-07:00 List-Id: On 11/18/2014 07:50 PM, Hubert wrote: > That basically is a vote for global objects. Whether they are accessed through a > global variable or some sort of getter function that returns access Most of us on here are talking about how to do it in Ada. However you do it in C++ will be different, because C++ lacks modules. In Ada, there would be no functions that return access. At some point you have some requirements for your game, and somewhere in them is something along the lines of "the game will keep track of this, that, and the other". In the design you make from these reqs you decide to meet this req with a DB object. It allows you to add new (Key, Value) pairs, update the value for a key, retrieve the value for a key, and delete the pair for a key. In the Ada implementation, you implement this object as a package: package Game.DB is procedure Add (Key : in Key_Value; Value : in Data_Value); procedure Update (Key : in Key_Value; Value : in Data_Value); function Value (Key : in Key_Value) return Data_Value; procedure Delete (Key : in Key_Value); end Game.DB; [I'm sure the reality is more complicated. No doubt there are many different kinds of (Key, Value) pairs.] This pkg would be part of a low-level layer in your S/W architecture. Anything in higher layers that needs to access the DB can with the pkg and call its subprograms. This is the "Package as Object" pattern in Ada. -- Jeff Carter "You empty-headed animal-food-trough wiper." Monty Python & the Holy Grail 04