Tracking instantiation when running an OOP program
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Andy Parker
il 12 Ago 2019
Commentato: Andy Parker
il 22 Ago 2019
I am fairly new to MATLAB and I have been given the job of developing the OO code of another programmer who has left the company (without leaving a phone number!). The software runs okay, but I need to make some changes. In order to do this, I will need a good understanding of how the code runs.
Is there a simple way of tracking the order of instantiations when OO code is run?
More generally, can anyone recommend a good book to help learning MATLAB OOP (apart from the official MATHWORKS guide - I will give that a try)?
0 Commenti
Risposta accettata
Guillaume
il 21 Ago 2019
With regards to "tracking the order of instantiations when OO code is run", the best way is to use the debugger with breakpoints in suitable location.
We've discussed recently a way to automatically track object instantiation and destruction but it is not something I'd recommend doing if you're new to matlab or oop in matlab.
Più risposte (2)
Yogesh Khurana
il 20 Ago 2019
Hi,
You can refer to the following links for learning material for OOPS concepts in MATLAB:
https://www.mathworks.com/help/pdf_doc/matlab/matlab_oop.pdf (it’s a very good resource for OOPS concepts to start with)
A Guide to MATLAB Object-Oriented Programming [Paperback], by Andy H. Register, is based on the old (pre-R2008a) object-oriented features of MATLAB.
Hope this helps!
3 Commenti
Adam
il 21 Ago 2019
Make sure you understand first how old the OOP code is. If it is done in the current OOP framework then don't spend money on a book about the pre-R2008a method of doing it as it will not be useful to you at all!
The first link is by far the most useful and the one from which I learned OOP in Matlab (albeit it was a hundred or so pages shorter back in those days!!)
Steven Lord
il 21 Ago 2019
In order to do this, I will need a good understanding of how the code runs.
Is there a simple way of tracking the order of instantiations when OO code is run?
I don't have a suggestion for the question you asked, but I do have a suggestion for your ultimate goal. You have legacy code (by the first of the modern interpretations on that Wikipedia page, "source code inherited from someone else") but it also sounds like the code may satisfy the definition from Michael Feathers, "code without tests".
If that's the case, I recommend starting by writing tests for the methods of those objects using the testing framework included in MATLAB. This may sound intimidating, but I think the script-based infrastructure shouldn't be too difficult to start with. Try looking at the Write Script-Based Unit Tests topic on the Script-Based Unit Tests page linked from the page above for an example of how to create and execute such a test.
Once you have a good collection of tests, running them as soon as you modify the class methods will increase the chances of detecting problems introduced by your modifications right away.
Function-based and class-based tests are more complicated than script-based tests but give increased functionality. The three different methods of testing can't coexist in the same test file, but as you learn more about MATLAB programming you could add function- and/or class-based test files to your suite alongside your script-based test files.
Vedere anche
Categorie
Scopri di più su Desktop in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!