Object-Oriented Programming
摘要
Most programming done using MATLAB is procedural, a coding paradigm focused on defining a step-by-step process to reach a desired state. This process is often performed using functions. MATLAB does, however, provide a second programming paradigm, known as object-oriented programming (OOP). OOP involves breaking sections of repeated code into classes, which themselves are collections of functions (called methods). Classes are useful for grouping together sections of code and functions that perform operations relating to the same concept or object. By grouping functions together, classes make it easier to hide and protect data from external functions and classes, which is known as encapsulation. Additionally, classes can be instanced (duplicated) to create multiple objects that have the same methods but unique instanced variables (properties), leading to a modular style of programming. The modularity of OOP becomes much more important and useful as the complexity and size of projects increase. This chapter discusses OOP and how it can be used to improve engineering programs and simulations.