I have a lot of friends who come from electrical / physical / mechanical engineering background, and are curious about what is OOP all about. They all know Matlab quite well, so they do have basic programming background; but they have a very hard time grasping a complex type system which can benefit from the concepts OOP introduces.Can anyone propose a way I can try to explain it to them? I'm just not familiar with Matlab myself, so I'm having troubles finding parallels. I think using simple examples like shapes or animals is a bit too abstract for those engineers. So far I've tried using a Matrix interface vs array-based / sparse / whatever implementations, but that didn't work so well, probably because different matrix types are already well-supported in Matlab.
How to explain OOP to a matlab programmer?
object oriented;matlab
Since 2008, Matlab supports object-oriented programming. So if they want to find out about OOP in a way they're familiar with, they may want to have a look at the Matlab documentation on OOP, especially the examples. A while ago, I was introducing some of my Matlab-using colleagues to OOP. Here are some examples I used.Importantly, everything you do with OOP, you can also do otherwise. What OOP allows you is to (1) make more awesome structures, (2) bundle code, and (3) make it easy to modularize code and to program faster. Structures with fields that automatically update themselves. For example, you store a coordinate in pixels (because you measure it on an image), but for distance calculations, you want to have it in microns. Storing both in a structure is problematic, because if you change one, you must not forget to change the other (and you will). Thus, you choose to store all coordinates in microns, which means that every time you need it in pixels, you have to convert, which is annoying and may be error-prone. With an object, you make coordinate in pixels a dependent property, the conversion becomes automatic, and you don't have to worry about updating two coordinates at the same time. Of course, you can do much more. For example, your structure could have an 'edit'-method, which pops open a GUI, so that you can easily edit values. Or it can have a save method that is called whenever a value in the structure changes. You can bundle functions with your data structure. For example, you can have a customized plot function for your data that you call plot(myDataStructure). Similarly, you can have customized disp methods, or even have your data processing methods be attached to your data. 