Applied Programming/Modules and Classes

This lesson introduces modules and classes.

Objectives and Skills
Objectives and skills for this lesson include:


 * Creating classes and modules
 * Managing git branches
 * building familiarity with Object-oriented Programming(OOP)

Readings

 * 1)  Modular programming
 * 2)  Object-oriented programming
 * 3)  Class diagram

Multimedia

 * 1) YouTube: Python Classes
 * 2) YouTube: Classes and Instances
 * 3) YouTube: Using Methods with Classes
 * 4) YouTube: Understanding OOP vs. Functional Programming
 * 5) YouTube: Classes in JavaScript
 * 6) YouTube: Python getter and setter Methods
 * 7) YouTube: Method Types in Python OOP: @classmethod, @staticmethod, and Instance Methods
 * 8) YouTube: Classes and Objects - Basics
 * 9) YouTube: Classes and Objects

Examples

 * /Python3/

Activities

 * 1) Review Gordon.edu: ATM Example Class Diagram. Depending on time available, develop one or more class modules for an ATM based on the diagram provided. If applicable, work together with your classmates and have each person implement a separate module and class.
 * 2) For each class module, include appropriate data validation and parameter validation. Add module and method documentation, consistent with the documentation standards for your selected programming language.
 * 3) If you are working as a class, read about git to learn more about team-based programming contribution management and a commonly used version control system.
 * Read: git - using branches

Lesson Summary
The UML specifies two types of scope for members: instance and classifier, and the latter is represented by underlined names.
 * Modular programming is a software design technique that emphasizes separating the functionality of a program into reusable, independent modules.
 * This concept is related to structured programming and object-oriented programming; all have the same end goal of deconstructing a comprehensive program into smaller pieces.
 * Modular programming refers to high-level decomposition of the code of an entire program into pieces, while structured programming to the low-level code use of structured control flow, and object-oriented programming to the data use of objects, a kind of data structure.
 * Languages that formally support the module concept include Ada, Algol, BlitzMax, C#, Clojure, COBOL, D, Dart, eC, Erlang, Elixir, F, F#, Fortran, Go, Haskell, IBM/360 Assembler, IBM i Control Language (CL), IBM RPG, Java, MATLAB, ML, Modula, Modula-2, Modula-3, Morpho, NEWP, Oberon, Oberon-2, Objective-C, OCaml, several derivatives of Pascal (Component Pascal, Object Pascal, Turbo Pascal, UCSD Pascal), Perl, PL/I, PureBasic, Python, Ruby, Rust, JavaScript, Visual Basic .NET and WebDNA.
 * Modular programming can be performed even where the programming language lacks explicit syntactic features to support named modules, like, for example, in C. This is done by using existing language features, together with, for example, coding conventions, programming idioms and the physical code structure.
 * With modular programming, concerns are separated such that modules perform logically discrete functions, interacting through well-defined interfaces.
 * When creating a modular system, instead of creating a monolithic application (where the smallest component is the whole), several smaller modules are written separately so that, when composed together, they construct the executable application program.
 * This makes modular designed systems, if built correctly, far more reusable than a traditional monolithic design, since all (or many) of these modules may then be reused in other projects. This also facilitates the "breaking down" of projects into several smaller projects.
 * Object-oriented programming is a language model based on the concept of objects. This approach to programming is an evolution of design practices that enabled the reuse of software.
 * The most popular object-oriented languages are class-based, meaning objects are instances of particular classes. The most popular OOP languages include Python, Java, JavaScript, C++, C#, Ruby, PHP, Object Pascal, Objective-C, and Swift.
 * 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.
 * Languages called "pure" OO languages, because everything in them is treated consistently as an object, from primitives such as characters and punctuation, all the way up to whole classes, prototypes, blocks, modules, etc.
 * They were designed specifically to facilitate, even enforce, OO methods. Examples: Python, Ruby, Scala, Smalltalk, Eiffel, Emerald, JADE, Self.
 * Objects can contain other objects in their instance variables; this is known as object composition.
 * For example, an object in the Employee class might contain (either directly or through a pointer) an object in the Address class, in addition to its own instance variables like "first_name" and "position".
 * Object-oriented programming entails the use of classes, a template for object instantiation. An object is a user-created data type that carries its own attributes (fields) and behaviors (methods).
 * Languages that support classes almost always support inheritance. This allows classes to be arranged in a hierarchy that represents "is-a-type-of" relationships. For example, class Employee might inherit from class Person. All the data and methods available to the parent class also appear in the child class with the same names.
 * Both object-oriented programming and relational database management systems (RDBMSs) are extremely common in software today. Since relational databases don't store objects directly (though some RDBMSs have object-oriented features to approximate this), there is a general need to bridge the two worlds.
 * OOP can be used to associate real-world objects and processes with digital counterparts. However, not everyone agrees that OOP facilitates direct real-world mapping or that real-world mapping is even a worthy goal, that a program is not a model of the world but a model of some part of the world.
 * In languages that support open recursion, object methods can call other methods on the same object, including themselves, typically using a special variable or keyword called this or self.
 * This variable is late-bound;
 * It allows a method defined in one class to invoke another method that is defined later, in some subclass thereof.
 * In the design of a system, many classes are grouped together in a class diagram that helps to determine the static relations between them. With detailed modelling, the classes of the conceptual design are often split into a number of subclasses.
 * classes diagrams are represented with three compartments:
 * The top compartment contains the name of the class.
 * The middle compartment contains the attributes of the class.
 * The bottom compartment contains the operations the class can execute.
 * Classifier members are commonly recognized as “static” in many programming languages. The scope is the class itself.
 * Attribute values are equal for all instances
 * Method invocation does not affect the instance’s state
 * Instance members are scoped to a specific instance
 * Attribute values may vary between instances
 * Method invocation may affect the instance’s state (i.e. change instance’s attributes)
 * To indicate a classifier scope for a member, its name must be underlined. Otherwise, instance scope is assumed by default.
 * Instance-level relationships consist of:
 * Dependency
 * Association
 * Aggregation
 * Composition
 * Class-level relationships
 * Generalization/Inheritance
 * Realization/Implementation

Key Terms

 * class
 * A blueprint for constructing an object—a set of variables and methods that defines an entity.


 * class diagram
 * A graphical representation of the structure of an object-oriented system that displays their attributes and relationships.


 * class methods
 * belong to the class as a whole and have access only to class variables and inputs from the procedure call.


 * class variable
 * A variable that belongs to an entire class; there is only one such variable shared between all objects.


 * encapsulation
 * The act of hiding implementation details, either to protect internal data or for the purpose of abstraction.


 * instance methods
 * belong to individual objects, and have access to instance variables for the specific object they are called on, inputs, and class variables.


 * instance variable
 * A variable that is unique and belongs to each instance of a class.


 * 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.


 * me, self, this
 * A keyword that refers to the current object of focus.


 * member variable
 * A variable that is either a class or instance variable.


 * method
 * A function that is defined inside a class.


 * object
 * A particular instance of a class.


 * object composition
 * is that objects can contain other objects in their instance variables.


 * pointer
 * A pointer references a location in memory. As an analogy, a page number in a book's index could be considered a pointer to the corresponding page.


 * private
 * An access modifier which limits external access.


 * property
 * An intermediary between a variable and a method, providing the functionality of both.


 * public
 * An access modifier which opens up external access.


 * Procedural programming
 * is a programming paradigm, derived from structured programming[citation needed], based upon the concept of the procedure call. Procedures, also known as routines, subroutines, or functions, simply contain a series of computational steps to be carried out.


 * static
 * A keyword used in some languages to designate a variable or method as shared between objects.


 * state diagram
 * is a type of diagram used in computer science and related fields to describe the behavior of systems.


 * UML
 * (Unified Modeling Language) is a picture of an object oriented system.


 * Variables
 * Store information formatted in a small number of built-in data types like integers and alphanumeric characters.