how can my app inherit from my classes

13 Ansichten (letzte 30 Tage)
Micke Malmström
Micke Malmström am 11 Jan. 2017
Kommentiert: Noah Griffiths am 30 Mär. 2021
I have a class that can do some computations on some imported data. Now I would like to create an app with buttons for the methods in my class. Since I cant edit the first line in the "App Designer":
classdef App1 < matlab.apps.AppBase
is there another way of making my app inherit the methods and properties from my class?

Akzeptierte Antwort

Guillaume
Guillaume am 11 Jan. 2017
The app (GUI) should not inherit methods from your class and it's a good thing matlab actually prevents it. This would be antithetical to the principle of OOP particularly encapsulation. The App class is designed to handle interaction with the GUI, nothing more. It certainly shouldn't expose the method of an unrelated class
The proper design is to have an instance of your class as public or private member( property) of the App class. You can instantiate that member at creation of the GUI (in the startup callback) and use its properties and methods anywhere from the app. So, the code would be something like:
classdef App1 < matlab.Apps.Appbase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
end
% Your own properties that you can edit:
properties (Access = private)
MyClass myobject % Description
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.myobject = MyClass(args);
end
end
  5 Kommentare
Xingguo WU
Xingguo WU am 30 Jun. 2020
Hi,
What's the practice to reuse custom UI components?
I wanted to inherit a panel class, and in this subclass I can already put other controls, finally to reuse this panel in main figure across different programs.
But seems I cannot inherit `matlab.ui.container.Panel`, error prompt saying something like "class not in the allowance list".
Noah Griffiths
Noah Griffiths am 30 Mär. 2021
classdef App1 < matlab.Apps.Appbase
Anyone aware what this syntax means.
Is the class instantiated inside the app designer or outside?
Does anyone know if app is a parameter passed into the class or is it not necessary? Trying to think in terms of how matlab usually forces the app parameter in functions in appdesigner

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by