Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
roth_stephan_clean_c20_sustainable_software_development_patt.pdf
Скачиваний:
29
Добавлен:
27.03.2023
Размер:
7.26 Mб
Скачать

Chapter 6 Modularization

The Whole Enchilada

Now that we have worked through all the principles helping developers find a good modularization for a software system, we lump them all together to see how they overlap, support each other, or interact with each other. Let’s recap once again.

The single responsibility principle (SRP) is an amplification of the general principle of cohesion, which we know from Chapter 3. It states that each module we create should have a clearly defined responsibility and perform only one task. To discover these responsibilities, it is strongly recommended to use a domain-centered method and perform domain analysis to approach the problem from a stakeholder’s perspective and to make the modules and their interactions a model of an excerpt of the real world. While doing this, we will discover modules that are on different levels of abstraction: Large components that are responsible for an entire sub-area, down to small modules that solve minor subtasks. This will lead us to a model as it is generally depicted in Figure 6-1; we get a hierarchical decomposition of our software system. Modules on the same hierarchy level should also have the same level of abstraction; remember the SLA principle.

After this general introduction to the topic of modularization, let’s now look at a programming paradigm that has been included in C++ from the very beginning and that supports the formation of modules: object-orientation.

Object-Orientation

The historical roots of object-orientation (OO) can be found in the late 1950s. The Norwegian computer scientists Kristen Nygaard and Ole-Johan Dahl carried out simulation calculations for the development and construction of Norway’s first nuclear reactor at the military research institute Norwegian Defense Research Establishment (NDRE). While developing the simulation programs, the two scientists noted that the procedural programming languages used for that task were not well suited for the complexity of the problems to be addressed. Dahl and Nygaard felt the need for suitable possibilities in those languages to abstract and reproduce the structures, concepts, and processes of the real world.

In 1960, Nygaard moved to the Norwegian Computing Center (NCC) that had been established in Oslo two years before. Three years later, Ole-Johan Dahl also joined the NCC. At this private, independent, and nonprofit research foundation, the two scientists

227

Chapter 6 Modularization

developed first ideas and concepts for an—from today’s point of view—object-oriented programming language. Nygaard and Dahl were looking for a language that was suitable for all domains and less specialized for certain fields of application, such as Fortran for numeric computations and linear algebra or COBOL, which is designed especially for business use.

The result of their research activities was the programming language Simula-67, an extension of the procedural programming language ALGOL 60. The new language introduced classes, subclassing, objects, instance variables, virtual methods, and even a garbage collector. Simula-67 is considered the first object-oriented programming language and has influenced many other programming languages, for example, the full

object-oriented programming language Smalltalk, which was designed by Alan Kay and his team in the early 1970s.

While the Danish computer scientist Bjarne Stroustrup worked on his PhD thesis Communication and Control in Distributed Computer Systems at University of Cambridge in late 1970, he used Simula-67 and found it pretty useful, but far too slow

for practical use. So, he began to search for possibilities to combine the object-oriented concepts of data abstraction from Simula-67 with the high efficiency of low-level programming languages. The most efficient programming language at that time was C, which had been developed by the American computer scientist Dennis Ritchie at Bell Telephone Laboratories in the early 1970s. Stroustrup, who joined the Computer Science Research Center of the Bell Telephone Laboratories in 1979, began to add object-oriented features, like classes, inheritance, strong type checking, and many other things to the C language and named it “C with Classes.” In 1983, the name of the language was changed to C++, a word creation by Stroustrup’s associate Rick Mascitti, whereby the ++ was inspired by the post-increment operator of the language.

In the following decades, object-orientation became the dominant programming paradigm.

Object-Oriented Thinking

There is a very important point that we need to bear in mind. Just because there are several programming languages available on the market supporting object-oriented concepts, there is absolutely no guarantee that developers using these languages will produce an object-oriented software design automatically. Especially developers who have worked with procedural languages for a long time often have difficulties with the

228

Chapter 6 Modularization

transition to that programming paradigm. Object-orientation is not a simple concept to grasp. It requires that developers view the world in a new way.

Dr. Alan Curtis Kay, who developed object-oriented programming language Smalltalk with some colleagues at Xerox PARC in the early 1970s, is well known as one of the fathers of the term “object-orientation.” In a documented discussion via email with the German university lecturer Dipl.-Ing. Stefan Ram from Freie Universität Berlin from the year 2003, Kay explained what makes object-orientation for him:

“I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages (so messaging came at the very beginning – it took a while to see how to do messaging in a programming language efficiently enough to be useful). (…) OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things.”

—Dr. Alan Curtis Kay, American computer scientist, July 23, 2003 [Ram03]

Biological cells are the smallest structural and functional units of all organisms. They are often called the “building blocks of life.” Alan Kay considered software in the same way a biologist sees complex, living organisms. This perspective of Alan Kay should not be surprising, because he has a bachelor’s degree in mathematics and molecular biology.

Alan Kay’s cells are what we call objects in OO. An object can be considered a “thing” that has structure and behavior. A biological cell has a membrane that surrounds and encapsulates it. This can also be applied to objects in object-orientation. An

object should be well encapsulated and offers its services solely through well-defined interfaces.

In addition, Alan Kay emphasized that “messaging” plays a central role for him in object-orientation. However, he does not define exactly what he means by that. Is calling a method named foo() on an object the same as sending a message named “foo” to that object? Or had Alan Kay a message passing infrastructure in mind, such as CORBA (Common Object Request Broker Architecture) and similar technologies? Dr. Kay is also a mathematician, so he could also mean a prominent mathematical model of message passing named Actor model, which is very popular in concurrent computation.

In any case and whatever Alan Kay had in mind when he talked about messaging, I consider this view interesting and, by and large, applicable to explain the typical

229