How to define a pattern more freely than interfaces in C #

Let's say I have a group of classes that generate documents from templates. For instance...

class CustomerInvoice
{
    public satic string TemplatePath 
    { 
        get { return @"C:\Templates\InvoiceTemplate.doc"; }
    }

    public static DocumentType DocumentType 
    { 
        get { return DocumentType.WordDocument; }
    }

    public static void Create(Customer customer, int orderNumber)
    {
         //...
    }
}

All these classes have the same method name, but not necessarily the method signatures.

For example, I may have

CustomerInvoice.Create(Customer customer, int orderNumber);
DespatchNote.Create(Customer customer, int orderNumber, Warehouse warehouse);
PackingLabel.Create(int orderNumber);

... or something else (trying my best to find reasonable examples).

Is there a mechanism in OO that determines which method names have a group of classes this way? I really think that I have a way to ensure consistent implementation and naming of a group of similar objects, so they are more intuitive for consumers. Would such a case be considered a valid / appropriate use of any such technique?

+3
source share
2

, . , , - . , - Create(object) Create(T) ( T, ), te.

+3

,

, API , , - , .

, , , . , StyleCop, FxCop NDepend, ( !). , NDepend

WARN IF Count == 0 IN SELECT METHODS WHERE NameIs "Create" AND IsStatic

( ) , - ( ) Create

+2

Source: https://habr.com/ru/post/1782750/


All Articles