Search code examples
ooptemplate-method-pattern

OOP - 'Default' bad class name?


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?


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)