dimanche 25 juin 2017

How to properly setup naming convention for classes and namespaces?

In every C# project I always end up with a same issue. For example, I have the following namespace

ProjectName.Application.Invoicing

and classes

class InvoiceResponse
{
   ....
   public InvoiceType invoice_type {get;set}
   ....
}
class InvoiceUpdateRequest
{
   ....
   public InvoiceType invoice_type {get;set}
   ....
}
class InvoiceType
{
   public int type_id {get;set;
   ....
}

Now I believe i have two options

1. namespace ProjectName.Application.Invoicing 
class InvoiceResponse {} 
class InvoiceUpdateRequest {} 
class InvoiceType {}

in case InvoiceType class is differently declared for InvoiceResponse and InvoiceUpdateRequest, i would need to have something like InvoiceResponseInvoiceType {} InvoiceUpdateRequestInvoiceType {} that can help me differentiate classes Problem here in case main class changes, all related classes/classnames should be updates in order to keep class name consistency

2. Split into different namespaces
namespace ProjectName.Application.Invoicing.InvoiceResponse
class InvoiceResponse {} in this case I would have to use same namespace/classname convention which is not recommended
class InvoiceType{} 
namespace ProjectName.Application.Invoicing.InvoiceUpdateRequest
class InvoiceUpdateRequest {} in this case I would have to use same namespace/classname convention which is not recommended
class InvoiceType{}

Aucun commentaire:

Enregistrer un commentaire