c# - Will the Factory Pattern solve my problem? -
I need to create some objects that implement a given interface, where the type of concrete implementation is being made NUm Value
This problem (C #) is OK:
public enum ProductCategory {modem, keyboard, monitor} public class SerialNumberValidatorFactory () {Public IserialNumberValidator CreateValidator (ProductCategory productCategory) { Switch (productCategory) {Case ProductCategory.Modem: New ModemSerialNumberValidator (); Case ProductCategory.Keyboard: New Keyboard Back SerialNumberValidator (); Case ProductCategory.Monitor: New Monitor SerialNumberValidator Return (); Default: New Logic Expression ("Product Type"), string.format ("Product category serial number is not supported for verification: {0}", productCategory))}}
But, what happens if concrete implementations have different constructor logic? I can not go into all the values for the SerialNumberValidatorFactory.CreateValidator ()
method, so how do I proceed?
I'm going to solve this by the
CreateValidator
method Are there. Start with the base IValidatorSettings
, then create IModemSerialNumberValidatorSettings
etc., your CreateValidator
then ProductType
and take the IValidatorSettings
Argument Your concrete classes for law-makers will take their own IXXXValidatorSettings
interface as the sole constructor logic.
In addition to this you can do this then make a IValidatorSettings
factory. I think the abstract factory is a factory that creates a factory to handle any type of set - not sure it will apply in your scenario.
Comments
Post a Comment