Nectar
✅ Confused when try to implement Factory Method
I'm learning design patterns starting from the factory method. what I'm confused about is the first initialization to be used as a reference to be manipulated, for example as follows:
https://hastebin.com/share/kohugizayu.csharp
These 3 variables are needed for the movement (and maybe initialization) of the player later and it looks like it should be done in each concrete product, so where should I declare these 3 variables in the factory method implementation? if I declare it in each concrete product it will look like duplication code.
Any suggestions?
Thanks
14 replies
ELI5 : Abstract Class vs Interface
I want to create some models for ORM, and these models have some properties in common such as Id, CreatedDate, CreatedBy, etc. I want to make these properties located in the abstract and later the derived class can be inherited by the abstract class that holds these properties. it should be noted that these properties will definitely have the same implementation. I was thinking that I should implement them in an abstract class because the implementation will always be the same, but I saw a codebase that has a similar structure using an interface instead of an abstract class. so, what should I choose? abstract class or interface? any advice or a more understandable explanation of the two would be useful. thank you!
11 replies