Filter löschen
Filter löschen

working with classes and packages, can I have one main folder?

11 Ansichten (letzte 30 Tage)
Hello all,
I am refactoring a large codebase, and my approach to organise things is to make a class which describes the top level, lets call it " top_lvl_obj ". Alongside this class definition I have a folder I made into a Package by adding a + sign next to it, lets call it " +utilities ".
To showcase how the object works I have a demo.m script, and so my workspace looks like:
+utilities
@top_lvl_obj
demo.m
Ideally I want to move the +utilities folder into the @top_lvl_obj in order to have a single source code folder next to the demo.m script. This does not seem to be possible, and I'm not certain if there is a way around it.
I might be missing something, but I think the @class_name folder use is not very practical since it essentially works for only one m file, so a folder has one file in it, and each classdef needs another folder, which is a not very elegant way to organise files.
Thank you in advance,
Andreas.

Akzeptierte Antwort

Steven Lord
Steven Lord am 4 Okt. 2018
Putting classes in directories whose names start with the @ symbol is not always required. Classes using the older class system must be defined in @ directories. As stated on this documentation page, classdef-based classes that split the class definition across multiple files must be implemented in an @ directory as well. This latter case would fall into the "Distribute the Class Definition to Multiple Files" approach on that documentation page.
If each of your classes is contained in one individual file, you don't need to have the @top_lvl_obj directory if you don't want. You could simply have top_lvl_obj.m in the same directory as demo.m and the +utilities directory. From the last big paragraph in your question, it sounds like your classes are organized in such a way that could take advantage of this approach. This is the "Create a Single, Self-Contained Class Definition File" approach on the documentation page to which I linked.

Weitere Antworten (0)

Kategorien

Mehr zu Adding custom doc finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by