how can my app inherit from my classes

14 vues (au cours des 30 derniers jours)
Micke Malmström
Micke Malmström le 11 Jan 2017
Commenté : Noah Griffiths le 30 Mar 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?

Réponse acceptée

Guillaume
Guillaume le 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 commentaires
Xingguo WU
Xingguo WU le 30 Juin 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 le 30 Mar 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by