Using abstract class or interface in state pattern
This is a further question raised from Choice of inheritance from class or
declaring fields.
So I have a class Product{...}; I would like to add states to them such as
isPromoted, isDiscounted , discount price etc. So in order to implement
them I came out with the following tries:
1) public interface IProductState{ decimal isDiscounted(); void
isPromoted(); ...etc } Then have class Product: IProductState{...}
2) Or declare a new class ProductState{...etc} and declare as member class
Product{ProductState pstate;}
To me it seems like both ways can encapsulate the state so I would like to
know which way is better.
No comments:
Post a Comment