Search code examples
oopactionscript-3naming-conventions

What is the purpose of a Manager Class?


I see a lot of classes labelled "Manager". How is a manager class used?

For example, does it get used by composition like this?:

var m: Mananger = new ManagerClass();
m.doSomething();

Solution

  • Classes like that are used to manage a set of objects of another class, which are often resources.

    For example, let's say you have a pool of database connections, each one represented by an object of DBConnection class.

    If your code needs to connect to DB via a pool of connections, it will merely ask DBConnection_Manager class for a new connection. Why do we need the manager class?

    The Manager class will consult its list of DBConnection objects, and determine if any of them is un-allocated, and return one. If all are allocated, it will either create one and add to the pool (subject to max connections allowed limit) or place the request on queue, or report back failure.

    ALL of this functionality is full hidden from the caller - the nitty-gritty details of managing the pool are the job of the Manager class.

    This is just a specific example, but the idea is that resource management is centralized and encapsulated withing a Manager class and the user code merely asks for "a resource".

    I'm not sure if there's a bona-fide "design pattern" for this approach, though I found at least one web page that says so: http://www.eventhelix.com/realtimemantra/ManagerDesignPattern.htm


    Update: in case of actionscript, such a class could be used to manage sounds, or event listeners, or GUI widgets (e.g. context menus)