Applied Programming/Modules and Classes
Overview
editModular Programming
editModular programming is an approach to programming that breaks down and compartmentalizes portions of code into independent, specialized functions. Ideally, these functions should be reusable and each function should only perform one specific, focused task. You can think of these essentially as "mini programs" within a given sample of code. Modularity also makes it easier to perform maintenance, as everything is self-contained. You can often update, modify, or outright replace functions without the need to adjust much of the remaining body of code. Modularity helps add structure to the project and often tends to make the code more readable.
Object-Oriented Programming (OOP)
editIn a similar way that Modular Programming aims to separate and organize segments of a program, the object-oriented approach to programming groups and quantifies similar variables together into classes and objects. A class can be thought of as the type of variable you are working with. Strings, Integers, and Booleans are examples of classes intrinsic to many programming languages. You can also add customized classes to programs, so long as you follow the languages syntax; such as Employees or Foods. A single Employee or Food would be an object in this analogy. Objects are merely individual instances of a class.
When you create an object you also provide attributes for that object. For example, if you were to create an object for employee you would probably include the individual's name, payrate, some contact information, and title or rank within the company. These traits can be specific to the object (instance variables) or the entire class (class variables) and a combination of both (member variables). John, Mary, and Mike are all employees. John is the is Manager, while Mike and Mary would be Shift Leads.
Objects are accessed somewhat like variables with complex internal structure, and in many languages are effectively pointers, serving as actual references to a single instance of said object in memory within a heap or stack. They provide a layer of abstraction which can be used to separate internal from external code. External code can use an object by calling a specific instance method with a certain set of input parameters, read an instance variable, or write to an instance variable. Objects are created by calling a special type of method in the class known as a constructor. A program may create many instances of the same class as it runs, which operate independently. This is an easy way for the same procedures to be used on different sets of data.[1]
It's important to understand that objects aren't merely a complex list or dictionary. They are codified and provide specific functionality much like modules. When an object contains a function, or can execute an action, it is referred to as a method.
Class Diagram
editActivities
editKeywords
edit- Class- A blueprint for constructing an object—a set of variables and methods that defines an entity.[2]
- Class Diagram- A graphical representation of the structure of an object-oriented system that displays their attributes and relationships[3]
- Class Methods- belong to the class as a whole and have access only to class variables and inputs from the procedure call.[2]
- Class Variable- A variable that belongs to an entire class; there is only one such variable shared between all objects.[2]
- Encapsulation- The act of hiding implementation details, either to protect internal data or for the purpose of abstraction.[2]
- instance Methods- belong to individual objects, and have access to instance variables for the specific object they are called on, inputs, and class variables.[2]
- Instance Variable- A variable that is unique and belongs to each instance of a class.[2]
- Library- When a program invokes a library, it gains the behavior implemented inside that library without having to implement that behavior itself. Libraries encourage the sharing of code in a modular fashion, and ease the distribution of the code.[2]
- Me, Self, This- A keyword that refers to the current object of focus.[2]
- Member Variable- A variable that is either a class or instance variable.[2]
- Method- A function that is defined inside a class.[2]
- Object- A particular instance of a class.[2]
- Object composition- describes objects that can contain other objects in their instance variables.[2]
- Property- An intermediary between a variable and a method, providing the functionality of both.[2]
- Variables- Store information formatted in a small number of built-in data types like integers and alphanumeric characters