Labs / Python OOP

The Most Beginner-Friendly Object Oriented Programming Tutorial on the Whole Network: 00 Introduction to Object Oriented Design Methodology

Author: Li Zisheng · Source: FreakStudio open documentation · License: CC BY 4.0

Contents

Abstract

This paper mainly compares procedure-oriented programming and Object Oriented programming, introduces the background of the software crisis, explains the origin of the design idea of Object Oriented programming, and gives a brief introduction to the Object Oriented methodology: OOA-OOD-OOP.

1.1 Procedural Programming and Object Oriented Programming OOP

In embedded development, we often use the C language for programming, treat the problems to be solved as a series of tasks that need to be completed, and function is used to fulfill these tasks; the focus of problem-solving is concentrated on functions, which is the so-called procedure-oriented programming.

In contrast, Object Oriented programming takes objects as the basic units of a program: an object encapsulates both data and the function that manipulates the data, while objects sharing the same attributes and operation methods are abstracted into a class. Taking the industrial manufacturing practice of casting casings and parts with molds as an example, a class corresponds to the mold, and an object corresponds to the part produced from that mold — that is, an instance of the class.

Taking putting an elephant into a refrigerator as an example, the difference between the two is shown in the following figure:

The Most Beginner-Friendly Object Oriented Programming Tutorial on the Whole Network: 00 Introduction to Object Oriented Design Methodology

1.2 The Software Crisis and the Proposal of OOP Ideas

"The most terrifying sight in prehistoric times was a group of giant beasts struggling for their last breaths in a tar pit. Close your eyes and imagine: you see a herd of dinosaurs, woolly mammoths, and saber-toothed tigers fighting desperately to break free from the tar's hold, but the more they struggle, the tighter the tar clings. No matter how strong or powerful they are, in the end, none can escape a fatal fate. Over the past decade, the software development of large-scale systems has been just like falling into such a tar pit. .. "

— Fred Brooks

Early programming languages, such as assembly language and the machine language consisting solely of 0s and 1s, were essentially machine-oriented. They began to argue that programming designs should adopt statements aligned with human habits and logical thinking, for instance, using add for addition operations, sub for subtraction operations, and cmp for comparing the magnitudes of two numbers.

However, the CPU instruction set, or assembly language, remains rather abstract, which gave rise to a natural demand: could we write programs following a human-friendly line of thinking and then have the written code automatically translated into machine language? Later, computer scientists discovered that all programs can be boiled down to three fundamental structures: sequence structure, selection structure, and loop structure.

So-called high-level programming languages such as Fortran and C emerged as the times require. Such languages focus on logical processing procedures, and when addressing programming problems, people often adopt the structured paradigm to complete software development. The software life cycle is divided into several stages: requirement analysis, general design, detailed design, programming and testing, with emphasis placed on the modular structure of the system, as well as module division, data transmission and invocation relationships between modules.

However, with the rapid growth of software requirements, the procedure-oriented design method makes it easier for large-scale software to be designed into spaghetti code, where long sequences of procedure calls are executed one after another, just like a single strand of spaghetti. When a large project is finally made up of countless such strands, it turns into a tangled ball of yarn, becoming extremely difficult to maintain and modify.

2003

In 1968, the term "Software crisis" was coined at an international academic conference hosted by the North Atlantic Treaty Organization (NATO) in Federal Republic of Germany. The well-known software crisis had broken out since the mid-1960s; to address the issue, NATO held two consecutive renowned conferences in 1968 and 1969, during which the concept of software engineering was put forward. In 1972, Edsger Dijkstra delivered a speech at the ACM Turing Award:

To put it bluntly, the root cause of the software crisis is this: when there were no machines, programming was not a problem at all; when we got computers, programming began to be a problem; and now that we have massive computers, programming has become an equally massive problem.

—Edsger Dijkstra, *Communications of the ACM*

1987 25

The software crisis has led people to realize that there is an essential difference between medium-to-large software systems and small-scale software:

The Most Beginner-Friendly Object Oriented Programming Tutorial on the Whole Network: 00 Introduction to Object Oriented Design Methodology

Software has existed for decades, and it was not until the Object Oriented technology emerged in the 1980s that part of the predicament in the software crisis was resolved. People began to re-examine the essence of software programming: apart from software for scientific computing or other specific purposes, most software is designed to solve real-world problems, such as enterprise inventory management, bank account processing, and so on.Therefore, the essence of software programming is that programmers enable real-world entities to operate on computers through code; since computer software is developed to solve real-world problems, the core focus of software programming should be the entities in the objective world themselves, rather than the programmers' way of thinking or computer instructions.

If the focus of software programming lies in the entities of the objective world themselves, how can programming languages better meet this requirement? This is where Object Oriented programming came into being, which puts forward the proposition that everything is an object: users, accounts and commodities in the objective world are objects; factories, adapters and observers that create, combine and associate these objects are also objects; when all these objects are analyzed, designed and developed, a software system is completed. This software system is flexible and powerful, and most importantly, it can be quickly updated and maintained in response to changing requirements.

1.3 Object Oriented Methodology

Object Oriented methodology is a systematic approach that applies Object Oriented ideas to the software development process to guide development activities, and it is a methodology based on the concept of "objects". For Object Oriented methodology, it divides software development into three distinct phases: analysis, design, and programming.

1.3.1 Object Oriented Analysis (OOA)

OOA, namely Object Oriented analysis method, refers to the approach that, after completing the systematic business investigation in the development process of a system, analyzes problems in accordance with the Object Oriented ideology and identifies the required objects as well as the interaction relationships between them. The analysis phase focuses on what needs to be accomplished, and the output of this phase is a set of requirements.

1.3.2 Object Oriented Design (OOD)

Object Oriented Design (OOD) refers to conducting system design using Object Oriented methodologies based on the OOA model, which is the process of translating these requirements into an implementation plan. Designers must name objects, define their behaviors, and specify which objects can execute the designated behaviors on other objects. The design phase focuses on how to accomplish the objectives, and the output of this phase is the implementation plan.

1.3.3 Object Oriented Programming (OOP)

Object Oriented Programming (OOP) is the process of translating a well-defined design into an executable program, which defines the attributes of objects with specific data structures and implements the algorithms represented by the service flowcharts with specific statements. The programs generated in the OOP phase can closely correspond to the OOD model.

The Most Beginner-Friendly Object Oriented Programming Tutorial on the Whole Network: 00 Introduction to Object Oriented Design Methodology
347622978

Document Acquisition

You can download the document via the following link:

https://github.com/leezisheng/Doc

1 0 19

This document mainly introduces how to use Python for Object Oriented programming, and requires readers to have a basic understanding of Python syntax and microcontroller development. Compared with other blogs or books that explain Python Object Oriented programming, this document is more detailed and focuses on embedded host computer applications. It takes the common serial port data transmission and reception, data processing, dynamic graph drawing and other functions between the host computer and the lower computer as application examples, and uses the Sourcetrail code software to visually read the code to facilitate readers' understanding.

https://github.com/leezisheng/Python-OOP-Demo

The Most Beginner-Friendly Object Oriented Programming Tutorial on the Whole Network: 00 Introduction to Object Oriented Design Methodology
347622978

Previous Recommendations:

For more information about the document, please refer to:

You who study embedded systems still don't know Object Oriented? ?!