Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

We all know that the hardest parts of computer science deal with cache invalidation and naming things; my problem is the latter.

I have a process that raises events when various things happen. Rather than creating all of the objects for all potential events before the process is started, I have created classes that create the necessary dependencies for the event when the event is called, then calls the next sub-process. I have no idea what to name these classes.

A typical example might include a logger, mailer and anything needed to render a view for that event, such as templates. Not every action needs these things or else I'd just create them and be done with it.

share|improve this question

closed as primarily opinion-based by gnat, GlenH7, Glenn Nelson, Dynamic, MichaelT Dec 17 '13 at 3:49

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

    
What is the name of class (or names of multiple classes) that this structure creates ? –  teresko Aug 15 '12 at 3:58
    
A typical example might include a logger, mailer and anything needed to render a view for that event, such as templates. Not every action needs these things or else I'd just create them and be done with it. –  Levi Morrison Aug 15 '12 at 4:00
1  
We all know that the hardest parts of computer science deal with cache invalidation and naming things Nope. That's actually easy. Cache is ALWAYS invalid and thing are named Foo and Bar ;) –  kaoD Aug 16 '12 at 6:35

2 Answers 2

up vote 3 down vote accepted

Seems like something I would call Dispatcher. And the basic pattern it is built on would be *Factory. Or if you really are creating classes with names Mailer and Logger , then it sounds like a ServiceFactory.

For a better name you would have to show some code.

share|improve this answer

If you want to make it easier for other programmers to read your code, consider naming related to creational patterns.

  • Note that other programmer may be you yourself, just few months / years later.
    "What the heck did I mean writing this back then, in mid 2012?"

Eg it's hard to go wrong with Factory naming, it immediately tells a lot to experienced code reader. LoggerFactory, MailerFactory etc.

    Mailer mailer = MailerFactory.newMailer()

If creation process involved is quite complicated, Builder could be a good fit.

    new MailerBuilder()
            .to(toParameter)
            .from(fromParameter)
            .subject(subjParameter)
            .build()

If creation is expected to be somehow "completed" at client code side, consider Prototype name.

    Logger logger = new LoggerPrototype() {
        // define method that was abstract in parent class
        void log(String message) {
            writeToConsole(message);
        }
    }
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.