how can my app inherit from my classes

조회 수: 13 (최근 30일)
Micke Malmström
Micke Malmström 2017년 1월 11일
댓글: Noah Griffiths 2021년 3월 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