Join Jungwoo Ryoo for an in-depth discussion in this video Understanding object-oriented programming, part of Python: Design Patterns.
- Object-oriented programming is a mainstream software development methodology today. The number of modern programming languages support object-oriented programming, including Python. In fact, design patterns rely heavily on the use of object-oriented programming. Therefore, design patterns are almost irrelevant to the non-object-oriented programming languages, such as see. Understanding the core concepts of object-oriented programming certainly involves the understanding of the concepts such as object, and classes.
Objects represent entities in both problem and solution domains. In other words, when you're building a piece of software you need to have elements or components representing all the moving pieces of your solution. In addition, you also need to represent all these entities interacting wtih the software in the problem domain. For example, let's think of a conference registration system. In this case, you can think of the conference participants as being in the problem domain, while the registration form the participants are using being in the solution domain.
You need both represented in your software. Classes are templates used to create objects to avoid creating these objects from scratch every time you need it. Think of classes as cookie cutters being used to replicate these objects every time you need them. Classes define objects in terms of attributes, and behaviors. Attributes, in this case, represent the properties of an entity. Attributes also capture the current state of the entity.
On the other hand, methods represent the behaviors of an entity. Let's go back and think about our registration system example one more time. In such a system participants have attributes such as age, while participants also have the behaviors, such as canceling the registration. Understanding the concepts such as classes and objects is critical in object-oriented programming.
Therefore, I'd like you to revisit this topic if you're unclear about what they truly mean.
- Understanding design patterns
- Best design practices: consistency, completeness, and correctness
- Working with creational patterns
- Working with structural patterns
- Working with behavioral patterns
Skill Level Intermediate
Q: In the strategy pattern example, why does the code keep executing the default function rather than the alternate?
A: The programming demonstration skips the step of defining what the strategy pattern should be when an alternate function name is provided
as an argument as shown below.