1

The following class defines a template for printing a order invoice to company 1.

Similarly, there are separate classes that define the template for printing order invoices to respective companies.

I have read questions asked on SO here, here, here and here where they emphasis this point:

Use a noun or noun phrase to name a class

But, for eg.

PrintTemplateClient1 (which is a verb) for naming a class seems to be fine for me rather than using a noun here.

Any ideas how to name this ?

Do kindly let me know if this question does not belong here so i can move to relevant forum.

Community
  • 1
  • 1
  • 4
    eg. `ClientTemplatePrinter`, or leave it as is – user2864740 Sep 17 '14 at 06:21
  • 5
    A "print template" is a noun. – Igby Largeman Sep 17 '14 at 06:21
  • @user2864740: `Client1TemplatePrinter` , `Client2TemplatePrinter`. So, we will have `Client*n*TemplatePrinter` classes ? – now he who must not be named. Sep 17 '14 at 06:23
  • @nowhewhomustnotbenamed. don´t you have these anyway, no matter on its actual word-order? However I also vote for Client1TemplatePrinter – MakePeaceGreatAgain Sep 17 '14 at 06:24
  • There isn't a lot of need I have ever found to add a `1` suffix to a class name (model issue?) – Sayse Sep 17 '14 at 06:29
  • @Sayse: Actually thats an example. A real one would be different `MyClientPrintTemplate` such that – now he who must not be named. Sep 17 '14 at 06:31
  • 1
    @nowhewhomustnotbenamed. If I needed to have a *different* class per client I would put the classes (per client) in a *different* namespace, with a more meaningful name, eg as a fetched example: `Report.UMBC.Generator` (where UMBC is an internally well-known/consistent monikor for the given client, and of course make sure to unify around Interfaces as appropriate). I would also look and possibly refactor such that only the code/model-generators that *needed* to be different were. – user2864740 Sep 17 '14 at 07:00

5 Answers5

4

I suspect the word "print" is confusing things here. You probably wouldn't think of it as a problem if it were PdfTemplateClient1 for example. However, I would try to put the noun at the end - I'd use Client1PrintTemplate, to go along with Client2PrintTemplate etc. The part that classes have in common usually comes at the end of the name rather than the start (e.g. TextReader, StreamReader, StringReader).

That said, I'd also try to avoid having different code for different companies in the first place... this sounds like the kind of thing that should be handled with data if at all possible - you might want different template renderers for different output formats, but I'd try to avoid them being different for different companies.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
3

You are already using a noun: PrintTemplate. A "print template" is a thing. The fact that the word "print" is also a verb does not change the fact that a "print template", which is a template for printing, is a noun.

Igby Largeman
  • 16,495
  • 3
  • 60
  • 86
1
I recommend changing the way you are defining your classes


    public interface IClientTemplate {

           GetTemplate(int templateTypeID, int clientID);

    }


    public class ClientTemplate: IClientTemplate {

        public string GetTemplate(.. get template as xml.. ) { }
    }


    public interface IPrintService {
              ClientInvoice(int clientID);
              ClientMemo(int clientID);
   }



public class PrintService: IPrintService {

        public ClientInvoice(int clientID) {

                 var template = new ClientTemplate ().GetTemplate(2, clientID);
                 .... and print her... 
            }

   }

With this approach you will be able be able to test the project. In addition, there is a modularity as well.

codebased
  • 6,945
  • 9
  • 50
  • 84
1

As a common rule, it's better if a class names reads in English revealing it's purpose. Name should start with an English sub-phrase representing a class, and end with a sub-phrase representing a abstract category of the class.

In your case, PrintTemplateClient does not read in English as something naming a 'Company-One client printing template'.

It could be CompanyOneClientPrintingTemplate, given there are templates exist for other companies, and they derive from common base class: class CompanyOneClientPrintingTemplate : ClientPrintingTemplate {} class CompanyTwoClientPrintingTemplate : ClientPrintingTemplate {}

It's perfectly ok to use whatever grammatical part of speach which reflects the purpose of a class.

For example, if a class represents command, it should start with a verb, and end with word Command, in case of a messaging-based system. (See CQRS Documents by Greg Young)

For example:

MakeClientReservationCommand - a class that represents a command which would result in action of making a reservation for a client, if carried out by a system.

A corresponding class representing an event that have happened as a result of a command should be a statement in past tense:

ClientReservationCreated ClientReservationRejected

As you can see, the names of the classes follow the general rule stated - they all read in plain English.

George Polevoy
  • 7,450
  • 3
  • 36
  • 61
0

Generally what has been recommended is on point, if you are having trouble thinking of a way to name your class try thinking about the class as a service and naming it after that, for instance:

ClientTemplateService, TemplatePrinterService,

etc...

DotNet NF
  • 805
  • 1
  • 6
  • 14