Substitution The Interface Segregation The Dependency Inversion Principle Statement A class should have only one reason to change. A class should be open for extension, but closed for modification. The sub-types must be substitutable for their supersets. The abstractions should not depend upon details. The details should depend upon abstractions. A client should not be forced to depend upon operations that it does not use. Also, an interface belongs to a client, not to the hierarchy. Table 1 . A collection of object-oriented design principles for classes. . 1 . SOLID SCOPE The default target for SOLID is a new design. However, if (1) a design ‘smell’ is discovered, and (2) it is possible to ‘refractors’, then SOLID, particularly those for classes, can also be used to improve the quality of an old (legacy) design, specifically the readability and maintainability of the source code. 2 4. In its first incarnation, a copy programs is supposed to accept characters as input from the keyboard, and provide a copy of them to a printer as output. There are three procedures in the copier program.

The Copy procedure calls the other two, namely he Readability that reads characters from the keyboard, and the Hereinafter that writes those characters too printer. The structure chart and the listing of the copy program are shown in Figure 1 and Figure 1 . The design of the first version of the copier program. // Copy Program: Incarnation I public class Copier { public static void Copy() { into c; while((c = Keyboard. Read()) -1) Printer. Write(c); Listing 1 . The C# source code of the first version of the copy program. 2 The program is in C# and could be modified for other members of the C family of languages.

Need essay sample on THE EVOLUTION OF A COPY PROGRAM ?We will write a custom essay samplespecifically for you for only $13.90/page

order now

However, the underlying programming language is not relevant to the discussion. 3 For the sake of this document, terms such as a function, module, procedure, routine, sub-program, and other similar constructs, are considered synonymous. 3 5. There is passage of time. There is a change in the input device requirements due to internal demands (coming from within the organization, such as, from other programmers). The copy program should also be able to read characters that are input from the Braille reader. The program in Listing 1 is not designed for a Braille reader.

To accommodate the hang in the input device, a Boolean argument is added to the Copy procedure. If True, it reads from the Braille reader; if False, it reads from the keyboard as before. A change in the interface is not feasible at this stage as, with the passage of time, several other programs use the copy program. To let the copy program know that it must read from the Braille reader, a global variables along with the ? : (ternary) operator are used. The result of accommodating the aforementioned changes is given in Listing 2. The use of global variables in programs is usually considered ‘poor’ practice because f their nonlinearity.

For example, a global variable can potentially be modified from variable has an unlimited potential for creating mutual dependencies and, in general, addition of mutual dependencies increases structural complexity. The use of global variables also adversely affects the readability and understandability of a program. There are programming languages, such as Java, that do not have global variables. (In Java, all variables that are not local variables are fields of a class. Hence, all variables are in the scope of either a class or a method. ) 5 The origin of the ?

from Nandarnold

Hey! So you need an essay done? We have something that you might like - do you want to check it out?

Check it out