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!feeder.eternal-september.org!news.glorb.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!fx14.iad.POSTED!not-for-mail From: Hubert User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: What is your opinion on Global Objects? Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 141117-1, 11/17/2014), Outbound message X-Antivirus-Status: Clean Message-ID: X-Complaints-To: abuse@newsdemon.com NNTP-Posting-Date: Tue, 18 Nov 2014 01:36:41 UTC Organization: http://www.NewsDemon.com Date: Mon, 17 Nov 2014 17:36:44 -0800 X-Received-Bytes: 3378 X-Received-Body-CRC: 984667510 Xref: news.eternal-september.org comp.lang.ada:23497 Date: 2014-11-17T17:36:44-08:00 List-Id: This is not an Ada matter per se, but since I see such a vigorous discussion about the OOP topic in this forum I thought I'd ask this question here which has kept me thinking for a while and I wasn't able to find a satisfying canonical statement on this. Some say this and others say that, so I think I'd ask for opinions here so that perhaps I can form my own at the end. Here is the question. Assume you have a large software system. Let's take the system for instance that I am involved in now as part of my work which is a multiplayer Client Server game. It is written in C++ but that shouldn't matter for the purpose of this topic. There are "entities" on the server side that need to be accessed nearly everywhere. These entities best fit the Singleton Pattern because there is really only one instance of them, ever. For instance the class that handles the internet access and all client connections. Or the Ram based database that holds all the game objects. There is also the representation of the 3D world on the server side which is used for position check and all sort of 3D information. These entities must be accessible from many locations in the code, although the region where access is needed can be somewhat restricted for instance the internet channel must be accessible for all player initiated actions but also by the User Agents that handle open windows on the player client and so on. So my question is basically, is it OK to make these entities available through global access variables, or should they all be passed as arguments to function calls? We all know global objects are bad (not to mention that theorists heftily denounce the Singleton Pattern as bad, but, hey there is only one way to the internet and only one database, I'm sorry) but we also know that it is bad to carry "tramp data" through multiple levels of function calls when the functions do nothing with that data but pass it on to lower functions. Global access can not really be tested in unit tests because they can not be passed as parameters. That's my greatest objection with the global concept but I dont want to pass 3, 4 or 5 parameters to every single function because a function called 5 levels below that call level might need access to those objects. I don't think there is a silver bullet here but I would really love to hear what others think about this problem, specifically in an environment and with the examples I have shown here. Thanks --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com