Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Praise for C# 2.0: Practical Guide for Programmers 2005 phần 8 pot
MIỄN PHÍ
Số trang
24
Kích thước
365.5 KB
Định dạng
PDF
Lượt xem
1623

Praise for C# 2.0: Practical Guide for Programmers 2005 phần 8 pot

Nội dung xem thử

Mô tả chi tiết

162 Chapter 7: Advanced Types, Polymorphism, and Accessors ■

Exercises

Exercise 7-1. Write an object-oriented version of the Unix word count wc utility (see

description in Exercise 6-3).

Exercise 7-2. Implement the common behavior of the ICounter interface in an abstract

Counter class. Hint: Only the process method (that compares each character read) stays

abstract in order to be implemented in three concrete classes CharCounter, LineCounter,

and WordCounter.

Exercise 7-3. Extract the behavior of a counter in an ICounter interface. Hint: At least

four methods are needed to count, process, reset, and get the counter value.

chapter 8

Collections and Generics

The mathematical library of the FORTRAN programming language was and still is

a fundamental strength of the language. Code that has been optimized and tested for

decades continues to serve the needs of scientists and engineers worldwide. Newer pro￾gramming languages, like Java and C#, are also supported by extensive libraries of reusable

code, reducing software design in many cases to a question of finding the right class with

the right behavior for the right job. This reuse of components is a practice of long stand￾ing in every engineering discipline. It is not surprising, therefore, that software reuse has

gained much more prominence over the last two decades as designers have shied away

from the risk of “reinventing the wheel” and embraced the security of reusing code that is

more reliable, more portable, and more maintainable.

Object-oriented technology is a perfect catalyst for software reuse based on its three

fundamental characteristics of classes, inheritance, and polymorphism. In this chapter,

we examine in greater depth the Framework Class Library (FCL) of .NET first mentioned in

Chapter 1. The FCL implements several traditional data structures, such as hash tables,

queues, and stacks, that are modeled in an object-oriented way via classes and interfaces.

Essentially, these classes and interfaces can be thought of as collections of objects that

are accessible and organized in specific ways, but which share a similar common behavior.

Although not part of the .NET Framework, generic classes naturally follow our discussion

on collections. They offer better compile-time type checking and, hence, greater runtime

efficiency over object collections.

8.1 Collections

As discussed in Section 4.7, an array is the simplest, and the only, data structure that is

directly part of the System namespace. Each array in C# inherits from the System.Array

163

Tải ngay đi em, còn do dự, trời tối mất!