how can my app inherit from my classes

14 次查看(过去 30 天)
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?

采纳的回答

Guillaume
Guillaume 2017-1-11
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 个评论
Xingguo WU
Xingguo WU 2020-6-30
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 2021-3-30
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by