MATLAB Answers

Tracking instantiation when running an OOP program

조회 수: 1(최근 30일)
Andy Parker
Andy Parker 12 Aug 2019
댓글: Andy Parker 22 Aug 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)?

채택된 답변

Guillaume
Guillaume 21 Aug 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.
  댓글 수: 1
Andy Parker
Andy Parker 22 Aug 2019
I have found that running the code step by step and making notes is good enough to give me the running information that I need for the moment. I'm getting there..

댓글을 달려면 로그인하십시오.

추가 답변(2개)

Yogesh Khurana
Yogesh Khurana 20 Aug 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
Andy Parker
Andy Parker 22 Aug 2019
I found a downloadable pdf of Andy Register's book. It's quite chatty and helpful for background and introduction to concepts, but I won't rely on it for syntax.
I will wade into the matlab_oop.pdf - there's no avoiding it..

댓글을 달려면 로그인하십시오.


Steven Lord
Steven Lord 21 Aug 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.
  댓글 수: 1
Andy Parker
Andy Parker 22 Aug 2019
The departed programmer left some test scripts which I am learning to work with. Thanks for the suggestion - when writing my own tests I will start off with script-based.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by