working with classes and packages, can I have one main folder?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Andreas Prokopiou
el 4 de Oct. de 2018
Respondida: Steven Lord
el 4 de Oct. de 2018
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.
0 comentarios
Respuesta aceptada
Steven Lord
el 4 de Oct. de 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.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Adding custom doc en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!