Tracking instantiation when running an OOP program
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Guillaume
2019-8-21
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.
更多回答(2 个)
Yogesh Khurana
2019-8-20
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 个评论
Adam
2019-8-21
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
2019-8-21
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!