Is there a design pattern for injecting methods into a class?
Posted
by
glenn I.
on Stack Overflow
See other posts from Stack Overflow
or by glenn I.
Published on 2011-02-01T23:13:04Z
Indexed on
2011/02/01
23:26 UTC
Read the original article
Hit count: 262
I have a set of classes that work together (I'm coding in javascript).
There is one parent class and a number of child classes that are instantiated by the parent class. I have a number of clients of these classes that each need to add on one more methods to the parent or child classes.
Rather than having each client inherit from these classes, which is doable but messy because of the child classes, I am having these clients pass functions into the parent class when they instantiate the main class.
The main class creates the methods dynamically and the clients can call the methods like they were there all along.
My questions are:
- is this a sensible thing to do?
- what would the design pattern be for what I am doing?
© Stack Overflow or respective owner