I have an interface with a method Validate() and an abstract class that implement this interface, and made a class called CustomerValidator that inherit the abstract class, also have entity Customer inherit CustomerValidator so i can call customer.Validate() in the library project.
my scenario is that i dont want the validate method to be available on the client code..if they new up a customer they should only see the entity properties..ex fistname ect. How do i hide the validate method? Thanks
I must also ask why
CustomerinheritsCustomerValidator, but also why isCustomerValidatorabstract? I would suggest you change your interface and implementation as follows:Then, if you insist on being able to do something like
I would suggest you use C# extension methods like this:
Note the
internalscope so that clients cannot use this call.As for using composition, I don’t think
Customershould know anything aboutCustomerValidatororICustomerValidator. Those external responsibilities are outside the scope of aCustomerclass. If anything,CustomerValidatorcan have aCustomerproperty if you insist on using composition, but I think the interface should take in aCustomerparameter instead.