Insights on Python (4)

Insights on Python (4)

Continuing from the previous article, after understanding class definitions and function definitions, we begin to learn about object-oriented programming, which has three main characteristics: encapsulation, inheritance, and polymorphism. Let’s learn about each of these: đź”’ Characteristic 1: Encapsulation The core idea: encapsulating data and methods together, hiding internal implementation details Detailed case: ATM machine class … Read more

Introduction to Object-Oriented Programming in Python: A Beginner’s Guide to the “Everything is an Object” Mindset

Introduction to Object-Oriented Programming in Python: A Beginner's Guide to the "Everything is an Object" Mindset

If you are just learning Python, are you still writing a bunch of messy functions? When you encounter repeated functionalities, do you copy and paste, and when you modify the code, does it affect everything? In fact, there is a more efficient programming method in Python—Object-Oriented Programming (OOP). It is like “bringing” real-world objects into … Read more

From C++ Function Pointers to Function Objects

From C++ Function Pointers to Function Objects

In the previous article, we introduced the relevant applications of function pointers and stated that they are a low-level language construct inherited from C. In C++, objects are used as a more powerful method than C-style function pointers, and these objects are called function objects. Similar to function pointers, function objects behave like functions, but … Read more

Python Classes and Inheritance

Python Classes and Inheritance

Introduction The mountains fade into the plains, and the river flows into the wilderness. Overview Basics of Classes Inheritance Polymorphism Encapsulation Multiple Inheritance Using the super() Function Class Methods and Static Methods <span>Property Decorators</span> <span>Abstract Base Classes</span> Basics of Classes What is a Class? A class is a template that describes the behavior and state … Read more

Exploring C++ Friend Functions

Exploring C++ Friend Functions

What is a Friend? A friend declaration appears within a class and grants a function or another class access to the private and protected members of the class that declares the friend (https://en.cppreference.com/w/cpp/language/friend.html). Points to note: Friend declarations are made within the class, but their specific location is not restricted and is not subject to … Read more

Building Complex and Flexible System Architectures with C Language

In complex embedded systems (such as multi-device driver frameworks, protocol stacks, state machines), good code organization is often required. By using structures and function pointers, we can simulate the three main characteristics of object-oriented programming in C language: Encapsulation, Inheritance, and Polymorphism. Implementation of Object-Oriented Concepts in C Encapsulation Principle: Encapsulate data and operations on … Read more

Three Encapsulation Methods for Function Macros in C Language

1 Introduction to Function Macros Function macros are macro definitions that contain multiple statements, typically encapsulating frequently called functionalities without the overhead of function calls, such as stack push and pop. Function macros are essentially macros and can be defined directly, for example: #define INT_SWAP(a,b) \int tmp = a; \ a = b; \ b … Read more

Advanced Python: 10. Classes and Objects

1. In Python, a class is a template for creating objects, defining the common attributes (data) and methods (behavior) of the objects; an object is an instance of a class, a concrete implementation of the class.The relationship between classes and objects: a class is like a blueprint for a car, specifying that the car should … Read more

Introduction to Object-Oriented Programming in Python (Classes/Objects)

Python is an object-oriented programming language. Almost everything in Python is an object, which has attributes and methods. Object-oriented programming is a very popular programming paradigm, which is a methodology of program design. In simple terms, it refers to the programmer’s understanding and perception of the program and the way they write code. It is … Read more

Is C Language an Object-Oriented Programming Language?

Is C Language an Object-Oriented Programming Language? Abstract Object-Oriented Programming (OOP) is a programming paradigm centered around “objects,” characterized by encapsulation, inheritance, and polymorphism. This article argues that C language is essentially a procedural programming language by comparing the core features of OOP with the language design of C, supported by authoritative literature and language … Read more