class - What are the factors to consider when choosing between interfaces and abstract classes? -


While designing my software, I started with the interface because it looks "standard" then I change to intangible sections Because they look better than the problem. Although I'm not sure whether I missed the idea or not at some of the ideas I liked this design. Apart from domain-specific issues, what I have thought is what are the more common factors when choosing between interfaces and abstract clusters?

I think the best option is to do both most of the time. This is not always possible when you rely on something in the base class. Both provide an intangible base class and an interface, allowing the maximum latitude by the implementers of your abstract , however, unless you need an implementer of the interface if you Required If something happens, you want to not provide exactly the interface - and you will also need to make sure that you The base class ensures that the action always happens ...

Negative to both: more goo

example pseudocode:

  Interface IVehicle {Zero PutCarInGear (Int Speed); } Intangible class vehicles: IVehicle {public zero PutCarInGear (int speed) {// base implementation}}  

Note that in this example, anyone can create their own class which is IVehicle and then pass it to anything that takes IVehicle . That object will not need a child of the vehicle abstract class. If, therefore, you were expected to be certain in the PutCarInGear () method, it is quite likely that this new class will not fulfill this expectation. However, as long as it never counts that in the case of the implementation of IVehicle , then it is the most abstract abstraction for both an abstract base class and an interface.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -