1.2 What object-oriented means
Outside of the world of software, an object is a tangible thing that we can sense, feel, and manipulate. The earliest objects we interact with are typically baby toys. Wooden blocks, plastic shapes, and over-sized puzzle pieces are common first objects. Babies learn quickly that certain objects do certain things: bells ring, buttons are pressed, and levers are pulled.
The definition of an object in software development is not terribly different. Software objects may not be tangible things that you can pick up, sense, or feel, but they are models of something that has an internal state, can do certain things, and responds when things are done to it. Formally, an object is a collection of data and associated behaviors.
Object-oriented programming means writing code directed toward modeling objects. This is one of many techniques used to describe the actions of complex systems. The overall behavior emerges from collaboration between objects. A complicated internal state is decomposed into the states of separate objects.
To do object-oriented programming well, there are some additional disciplines. These include object-oriented analysis, object-oriented design, and even the combined and streamlined object-oriented analysis and design. All of these disciplines use the foundational concept of software objects and their interactions to analyze a problem and design a solution. Object interactions include creating objects, changing their values, and associating them with other objects.
Analysis, design, and programming are all stages of software development. Calling them object-oriented clarifies what kind of modeling techniques will be employed.
Object-oriented analysis (OOA) is the process of looking at a problem and identifying the objects and interactions between those objects. The analysis stage is all about describing what needs to be done.
The output of the analysis stage is a description of a problem and a solution to the problem, often in the form of requirements. If we were to complete the analysis stage in one step, we would have turned a task, I am a botanist and need a website to help users classify plants so I can help with correct identification, into a set of required features. As an example, here are some requirements for what a website visitor might need to do. Each item is an action bound to an object; we’ve written them with italics to highlight the actions, and bold to highlight the objects:
-
Browse previous uploads
-
Upload new known examples
-
Test for quality
-
Browse products
-
See recommendations
In some ways, the term analysis can be a misnomer. A baby interacting with objects doesn’t analyze the blocks and puzzle pieces. Instead, they explore their environment, manipulate shapes, and see where they might fit. A better turn of phrase might be object-oriented exploration. In software development, the initial stages of analysis include exploration: interviewing customers, studying their processes, and eliminating possibilities that don’t solve the problem.
Object-oriented design (OOD) is the process of converting such requirements into an implementation specification. The designer must name the objects, define the behaviors, and formally specify which objects can activate specific behaviors in other objects. The design stage is all about transforming what should be done into how it should be done.
The output of the design stage is an implementation specification. If we were to complete the design stage in a single step, we would have turned the requirements into a set of specifications for object classes. The specification might include state transition diagrams, collaboration diagrams, activity diagrams, and other useful details to describe state and behavior. These are ready to be implemented in (ideally) an object-oriented programming language.
Object-oriented programming (OOP) is the process of converting a design into a working program. This program does what the product owner originally requested during the analysis phase.
It would be lovely if the world met this ideal. If it did, we could follow these stages one by one, in order, as a well-defined method for producing software. As usual, the real world is much murkier. No matter how hard we try to separate these stages, we’ll always find things that need further analysis while we’re designing. When we’re programming, we find features that need clarification from further design.
Most modern software development practices recognize that a cascade (or waterfall) of stages doesn’t work out well. What seems to be better is an iterative development model. In iterative development, a small part of the task is analyzed, designed, and programmed. The developers can be said to form a scrum (or “scrummage”, as in the game of rugby), where the team members all push in one direction in concert. The resulting product increment is reviewed. Iterative development uses repeated cycles of improving existing features and adding new features. The scrum methodology emphasizes this periodic reset of the team followed by the focused pursuit of a near-term goal. At some point, the product is usable. Development is never really finished, but at some point it becomes clear that the cost of making any improvement will outweigh the benefits.
The rest of this book is about OOP. In this chapter, we will cover the basic object-oriented principles in the context of design. This allows us to understand concepts without having to work through Python language features at the same time.