Home How to make a container class than is able to call all class functions and apply them on all contained objects?
Reply: 0

How to make a container class than is able to call all class functions and apply them on all contained objects?

user869
1#
user869 Published in April 23, 2018, 8:57 pm

I have a class 'classB' that contains multiple objects of classA as a property. classB contains the same methods as classA but applies them on all ClassA objects it contains. Is there a way to do this in a single classB function instead of adding them all with a for loop?

classdef ClassB
    properties
         ClassAObj{1:3} %cell containing multiple class A objects
    end
    methods
        function function1(ClassB)
             for k = 1:numel(ClassAObj)
                 obj.ClassAObj{k}.function1 
             end
        end
        function function2(ClassB)
             for k = 1:numel(ClassAObj)
                 obj.ClassAObj{k}.function2 
             end
        end
        function...        
    end
end


classdef ClassA
    methods
        function1
        function2
        function...
    end
end
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.545256 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO