- When should
implement
orextend
be used? - What are some real-world examples?
Is this correct?
Implementing appears to be a way to enforce that certain methods exists in a class, and that these methods function calls are properly formatted. Implementing is not a way of passing variables or "settings" to the class though?
Expected real-life scenario: I have an e-commerce platform featuring multiple payment classes that all follow the same design. When a new payment class should be added, it's really easy to follow the defined design of the interface
to ensure that all bits and pieces are there, from the beginning.
Extending classes makes the extended (child?) class inherit everything from its parent class except methods & variables declared as private
?
Expected real-life scenario: I have one class called sessions
with two child classes named sessioncookies
and databasesessions
. sessioncookies
and databasesessions
, together inherit a number of mutual config options from their parent sessions, making it easy to change a config option to affect all sorts of eventual visitor data storage.