Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Daniel Solis - Illustrated C# 2010 - 2010.pdf
Скачиваний:
16
Добавлен:
11.06.2015
Размер:
11.23 Mб
Скачать

CHAPTER 19 GENERICS

Comparing the Generic and Nongeneric Stack

Table 19-1 summarizes some of the differences between the initial nongeneric version of the stack and the final generic version of the stack. Figure 19-8 illustrates some of these differences.

Table 19-1. Differences Between the Nongeneric and Generic Stacks

Nongeneric

Generic

Source Code Size

Larger: You need a new

 

 

implementation for each type.

Executable Size

The compiled version of each

 

 

stack is present, regardless of

 

 

whether it is used.

Ease of Writing

Easier to write because it’s more

 

 

concrete.

Difficulty to Maintain

More error-prone to maintain,

 

 

since all changes need to be

 

 

applied for each applicable type.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Smaller: You need only one implementation regardless of the number of constructed types.

Only types for which there is a constructed type are present in the executable.

Harder to write because it’s more abstract.

Easier to maintain, because modifications are needed in only one place.

Figure 19-8. Nongeneric stack versus generic stack

477

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]