フィルターのクリア

Can I import classes in an interface class in matlab?

6 ビュー (過去 30 日間)
ana take
ana take 2018 年 1 月 10 日
編集済み: Nikolaus Koopmann 2023 年 8 月 2 日
Hello everyone! Can I import other classes like BaseStation,Technology and Area in the interface class BsGridFactory which are in the datatypes package and the interface class is in another package? or I should import this classes in the implementation functions of subclasses of BsGridFactory?
createBaseStationGrid takes a users parameter which is an array of User objects, an area which is an Area object and a technology which is Technology object. Is the interface class written ok or should I remove the import statements? Thanks in advance!

採用された回答

Guillaume
Guillaume 2018 年 1 月 11 日
編集済み: Guillaume 2018 年 1 月 11 日
I'm not sure what you mean by import.
All import does is to allow you to refer to functions and classes in packages without having to specify the name of the package. So if you have
import datatypes.BaseStation
that means you can then write
someresult = BaseStation.SomeFunction(somearguments);
instead of
someresult = datatypes.BaseStation.SomeFunction(somearguments);
That is all. So in a context of an interface that only has abstract methods the import are useless since you're not calling any function anyway.
  1 件のコメント
ana take
ana take 2018 年 1 月 11 日
In OOP languages like Java you have to import classes in the interface class(if you use an object of these classes as parameters of the method defined in the interface class), that's why I wanted to clarify my doubts.Thank you for your answer!

サインインしてコメントする。

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2018 年 1 月 11 日
You can import inside of the individual methods of a class but not globally for the whole class.
classdef x
methods
function foo(obj)
import whatever.myclass
myclass(3)
end
end
end
  5 件のコメント
Ashley Trowell
Ashley Trowell 2021 年 7 月 16 日
Unfortunately, the import statement essentially obfuscates code, since it breaks the Ctrl + D functionality. The IDE doesn't seem to know where the code is defined. If you Ctrl + D on a imported function, you are told that it hasn't been defined, or are directed to a non package version, a version that won't actually be executed at runtime.
An import statement is critical for efficient development, but is a seriously broken feature in Matlab.
Nikolaus Koopmann
Nikolaus Koopmann 2023 年 8 月 2 日
編集済み: Nikolaus Koopmann 2023 年 8 月 2 日
This! One of the most annoying aspects of writing OOP code in Matlab..

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by