Applied Programming/Modules and Classes
This lesson introduces modules and classes.
Objectives and SkillsEdit
Objectives and skills for this lesson include:
- Creating classes and modules
- Managing git branches
- building familiarity with Object-oriented Programming(OOP)
- YouTube: Python Classes
- YouTube: Classes and Instances
- YouTube: Using Methods with Classes
- YouTube: Understanding OOP vs. Functional Programming
- YouTube: Python getter and setter Methods
- YouTube: Method Types in Python OOP: @classmethod, @staticmethod, and Instance Methods
- YouTube: Classes and Objects - Basics
- YouTube: Classes and Objects
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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 UML specifies two types of scope for members: instance and classifier, and the latter is represented by underlined names.
- Classifier members are commonly recognized as “static” in many programming languages. The scope is the class itself.
- 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:
- Class-level relationships
- 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.
- 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.
- 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.
- A function that is defined inside a class.
- A particular instance of a class.
- object composition
- is that objects can contain other objects in their instance variables.
- 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.
- An access modifier which limits external access.
- An intermediary between a variable and a method, providing the functionality of both.
- An access modifier which opens up external access.
- Procedural programming
- is a programming paradigm, derived from structured programming, 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.
- 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.
- (Unified Modeling Language) is a picture of an object oriented system.
- Store information formatted in a small number of built-in data types like integers and alphanumeric characters.
- Wikipedia: Modular programming
- Wikipedia: Object-oriented programming
- Wikipedia: Class diagram
- "Library (computing)" (in en). Wikipedia. 2018-06-05. https://en.wikipedia.org/w/index.php?title=Library_(computing)&oldid=844509652.
- "Pointer (computer programming)" (in en). Wikipedia. 2018-07-07. https://en.wikipedia.org/w/index.php?title=Pointer_(computer_programming)&oldid=849208568.
- Wikipedia: Access modifiers
- Wikipedia: Procedural programming
- Wikipedia: State diagram
- Wikipedia: Unified Modeling Language