Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7689871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:15:53+00:00 2026-05-31T20:15:53+00:00

Let we have one abstract class: classdef ACalculation < handle methods (Abstract) [result] =

  • 0

Let we have one abstract class:

classdef ACalculation < handle

    methods (Abstract)
        [result] = calculate (this, data);

        plot (this, data, limX, limY);
    end

end

And some other classes that implements ACalculation

classdef Maximum < ACalculation

    methods
        function [result] = calculate (this, data)
            %...
        end

        function plot (this, data, limX, limY)
            %...
        end
end

To functions of implementation class i give all needed information, so i don’t need any properties.
So it looks like I need static classes. But if I have static classes I have a problem with calling this functions.
I’d like to do something like that:

criteria = Maximum();
%......
result = criteria.calculate(data);

Is it bad way to use inheritance?
Should I ignore matlab advices to change functions to static?
What else could I do here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:15:55+00:00Added an answer on May 31, 2026 at 8:15 pm

    I think that in this case, static interface implementation is quite a good pattern.
    Define your classes in the following way:

    classdef ACalculation < handle
    
        methods (Abstract,Public,Static)
            [result] = calculate (data);    
            plot (data, limX, limY);
        end
    
    end
    
    classdef Maximum < ACalculation
    
        methods (Public,Static)
            function [result] = calculate (data)
                %...
            end
    
            function plot (data, limX, limY)
                %...
            end
    end
    

    Then, you can write a function that expects an ACalculation type:

     function foo(acalc,data)
          assert(isa(acalc,'ACalculation'));
          acalc.calculate(data);
          acalc.plot(data,[100 200]);
     end
    

    Then create a Maximum empty instance and pass it to foo:

     foo ( Maximum.empty(0), [1 2 3]);
    

    If you want to change the calculation method, call

     foo ( Minimum.empty(0), [1 2 3]);
    

    When you say that such a pattern will not work, you are thinking like Java/C#/C++ developer. But unlike in C++ where static and virtual keyword cannot coexist, Matlab has no such limitation, because everything is done at runtime, and an “instance” can be empty or an array of n elements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have this class: public abstract class CustomerCollectionBase : Collection<Customer>{} One of
I have one abstract class -let's say myBase. And I want all the classes
Let's suppose I have xml like this one: <Server Active=No> <Url>http://some.url</Url> </Server> C# class
I have one abstract class and two implementations. Let's call them ParentAbstract , ParentA
Let's say I have an abstract base class that looks like this: class StellarObject(BaseModel):
Let's say I have one class Foo that has a bunch of logic in
Let's say I have two models, Classes and People. A Class might have one
Let's say I have two strings: one is XML data and the other is
Let's say I have this in one of my targets: <path id=files> <fileset dir=${env.DIRECTORY}
Let's say you have a text file like this one: http://www.gutenberg.org/files/17921/17921-8.txt Does anyone has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.