Extending an Inheritance Hierarchy

Mở rộng một cấp bậc Inheritance Trong tập thể dục sau đây, bạn sẽ tự làm quen với một hệ thống cấp bậc nhỏ của giao diện và các lớp học đó cùng nhau thực hiện một khuôn khổ rất đơn giản. khuôn khổ là một Microsoft Windows ứng dụng mô phỏng đọc một C # nguồn tập tin và phân loại nội dung của nó vào thẻ | Extending an Inheritance Hierarchy In the following exercise you will familiarize yourself with a small hierarchy of interfaces and classes that together implement a very simple framework. The framework is a Microsoft Windows application that simulates reading a C source file and classifying its contents into tokens identifiers keywords operators and so on . The framework provides a mechanism for visiting each token in turn performing various tasks. For example A displaying visitor class that displays the source file in a rich text box. A printing visitor class that converts tabs to spaces and aligns braces correctly. A spelling visitor class that checks the spelling of each identifier. A guideline visitor class that checks that the public identifiers start with a capital letter and that interfaces start with a capital I. A complexity visitor class that monitors the depth of the brace nesting in the code. A counting visitor class that counts the number of lines in each method the number of members in each class and the number of lines in each source file. Understand the inheritance hierarchy and its purpose 1. Start Microsoft Visual Studio 2005. 2. Open the Tokenizer project located in the Microsoft Press Visual CSharp Step by Step Chapter 12 Tokenizer folder in your My Documents folder. 3. Display the source file in the Code and Text Editor window. The SourceFile class contains a private array field called tokens private IVisitableToken tokens new KeywordToken using new WhitespaceToken new IdentifierToken System new PunctuatorToken . The tokens array contains a sequence of objects that all implement the IVisitableToken interface. Together these tokens simulate the tokens of a simple hello world source file. A complete version of this project would parse a named source file and construct these tokens dynamically. The SourceFile class also contains a public method called Accept. The Accept method has a single parameter of type ITokenVisitor. The body .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.