Define Method Implementation During Construction
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I'm looking for a way of constructing an object depending on configuration. Basically, I have something like this
classdef MyClass < handle
...
methods
...
function foo = foo()
do something
end
function boo = boo()
do something
end
end
end
The properties of the class are the same, and I expect every instance of this class to have the foo and boo methods. However, I have multiple possibilities for these methods. Say for each I have 3 different implementations, which I can combine, giving a total of 9 behaviours for class MyClass. One example is: foo can either do some computations and output a value, or it can read this value from a table, or it can generate a random number. I also can at any time create a new implementation, like generating a random number but this time with a different distribution, so it would be nice to have each implementation in a different file.
What I want to do is to construct an instance of this class by saying: implement foo like this and boo like this.
Are there any suggestions?
0 comentarios
Respuestas (1)
Abhijeet
el 19 de Jun. de 2022
Hi Rodrigo Fischer ,
I can understand that you want to construct an object with different functionalites based upon diffrent use cases.
In design pattern there is Strategy Pattern which can be used for such scenarios.
Sharing some resources :-
0 comentarios
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!