Question

I am implementing a template method type of pattern and have several classes to implement the behaviour.

As an example, my structure is as follows:

TemplateAbstract
    Type 
        CustomType1
        CustomType2
        CustomType3
        Default

The 'Default' class holds the behaviour should none of the custom types be needed. My question is, is 'Default' a bad name for the class?

I guess, since I am asking this question, I already have some serious doubts over the name, but what else would you call a class that provides the default behaviour amongst types?

Was it helpful?

Solution

For sake of example, do you mean something like this?

Number
  Integer
    PositiveInteger
    NegativeInteger
    OddInteger
    EvenInteger

As Tom B pointed out in his comment, how you approach this depends on composition or inheritance; but I assume given this structure you laid out you mean to use inheritance. In my example having a "DefaultInteger" type seems rather awkward to use, but in your particular problem it may not be. And if Integer is just an interface a StandardInteger could make sense. Think about how a developer will use this type, and whether a "Default" makes sense as its own, separate thing:

Bread
  YeastLeavened
    Wheat
    TwelveGrain
    Default

Now I'm not sure what a Default yeast-leavened bread would be, but if it's a useful construct to your Baking program, then there's nothing inherently 'wrong' about it. Although I personally prefer to not have Default as its own type and instead just have a method on YeastLeavened.getDefault() to return the correct one.

Edit: So to answer your question directly, in general yes I would say "Default" is bad name unless you're always using it via a scope (Integer::Default), and in general is a hard class to have on its own conceptually (it's either abstract base functionality, or some concrete, "real" class functioning as what is used by default in the system)

OTHER TIPS

Just expand upon the name, call it:

DefaultTypeBehaviour

That is very unlikely to cause a conflict, and tells you a little bit more about what the class does.

Ideally, the class name should describe the purpose. "Default" is a vague term and doesn't have any significance with the functionality the class provides.

You can name your Default class something which tells that "this class has all the basic features implemented"

e.g. You can put the name something like "BaseType" or "BasicType" or "SimpleType" or anything else suits your need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top