So, I have several "Manager" classes, for example GroupManager. All these managers are singlets.
Using this method for instancing:
private static GroupManager groupManager = null; private GroupManager() { } public static GroupManager Instance() { if (groupManager == null) { groupManager = new GroupManager(); } return groupManager; }
I think I should start using some inheritance, since they have many copied methods.
Instance () methods are the same for each Manager.
So, for inheritance, I can do this (obviously):
GroupManager extends Manager
Is it possible to use generics to use the same Instance method for all managers, for example:
public class Manager<E> { private static E instance = null; public static E Instance() { if (instance == null) { instance = new E(); } return instance; } }
I think that makes sense :)
So, you would do GroupManager.Instance () as usual.
Metalstorm
source share