Reputation: 57
For my android/java application I came up with the following architecture:
Instead of storing objects as attributes in the classes where they belong to (e.g. view and model stored in the controller), each of my classes only stores a reference to an object named "appgeneral". The appgeneral object then contains all the objects as attributes for the whole application (e.g. view, model, controller, logging, validator etc.), including all data and some general methods such as error reporting. The advantage: When I create new objects, I just need to pass one object reference and store it and then I am able to access all the data and methods from everywhere. No more pain that some operations are not reachable just for design reasons of the application.
On the one hand, I think it is a good idea, but on the other hand, as I am quite new to software development, I am sceptic because I have nobody seen doing it that way.
But are there any serious disadvantages? As I said, I am wondering why not more people do it that way.
Thank you.
Upvotes: 1
Views: 108
Reputation: 6640
For a very small application, your design makes sense, but the larger a program gets, the more complex the code will become, hence a very well designed structure is required to maintain an overview of what does what.
In a bigger project, collecting many references to other objects in one object, where many of the different objects are unrelated, you will quickly loose the overview of what reference does what and is needed where. If you change anything in your code, it will be unclear, even to you as the author, if you need to remove certain references or not.
Moreover, you might create memory issues: you have to keep track of when to release/set null your references in the reference-collecting-object. If you fail to do so, you create a memory leak.
Upvotes: 2