***Sorry for clicking "Edit Post" like 20 times, but I kept thinking of more ways interfaces really help here.
Code to interfaces, not concrete implementations?
publicinterfaceIEngineer{//Engineer Properties}publicclassLeadEngineer:IEngineer{//Lead Implementation}publicinterfaceIAssemblyLineInstructions{}publicclassSedanAssemblyLineInstructions:IAssemblyLineInstructions{}publicinterfaceIVehicle{}publicinterfaceIAssemblyLine{}publicclassAssemblyLine{privateIVehicle_vehicle;privateIEngineer_enginee;privateIAssembyLineInstructions_instructions}publicinterfaceIFactory{publicIAssemblyLine{get;}}publicinterfaceINamedFactory:IFactory{stringFactoryName{get;}}publicabstractclassVehicleFactory:INamedFactory{publicstringFactoryName{get;set;}publicIAssemblyLineAssemblyLine{get;set;}}publicvoidPrint(INamedFactoryfactory){Console.WriteLine($"Welcome to {factory.FactoryName}");Console.WriteLine($"The Engineer on duy is {factory.AssemblyLine.Engineer.Name}");}publicclassSedanAssemblyLine:IAssemblyLine{//Assembly lines have engineerspublicIEngineerEngineer{get;set;}publicSedanAssemblyLine(){// Set defaults in the constructor, not using generics.// This assembly lines engineer is a SedanEngineerEngineer=newSedanEngineer();}}
if you have functionality that you're wrapping, that's fine too.
define an abstract class that contains common functionality, and make sure it implements the interface, then just subclass it and set your custom implementations in the constructors of base classes
publicinterfaceIFactory{publicIAssemblyLineAssemblyLine{get;}publicvoidPrintEngineer();}publicabstractclassFactory:IFactory{publicIAssemblyLineAssemblyLine{get;set;}//All factories will do this, in the same way, so Don't Repeat YourselfpublicvoidPrintEngineer(){Console.WriteLine("The engineer is ${AssemblyLine.Engineer.Name}");}}publicclassSedanFactory:Factory{publicSedanFactory(){//Sedan Factories have Sedan Assembly Lines... Obviously....AssemblyLine=newSedanAssemblyLine();}}
That is exactly how I would approach the problem. This approach is a combination of SOLID principles (interface segregation and dependency inversion mostly) and Bridge pattern (decouple an abstraction from its implementation so that the two can vary independently). Also,
"if you have functionality that you're wrapping, that's fine too.",
we can use Template pattern here.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
***Sorry for clicking "Edit Post" like 20 times, but I kept thinking of more ways interfaces really help here.
Code to interfaces, not concrete implementations?
if you have functionality that you're wrapping, that's fine too.
define an abstract class that contains common functionality, and make sure it implements the interface, then just subclass it and set your custom implementations in the constructors of base classes
That is exactly how I would approach the problem. This approach is a combination of SOLID principles (interface segregation and dependency inversion mostly) and Bridge pattern (decouple an abstraction from its implementation so that the two can vary independently). Also,
"if you have functionality that you're wrapping, that's fine too.",
we can use Template pattern here.