ebook img

Core C++: A Software Engineering Approach PDF

1189 Pages·2000·4.532 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Core C++: A Software Engineering Approach

file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm Core C++ A Software Engineering Approach Victor Shtern Publisher: Prentice Hall PTR First Edition July 24, 2000 ISBN: 0-13-085729-7, 1280 pages Master C++ the right way: From the software engineering perspective! l Master C++ the right way! Front Matter l Object-oriented approach to coding throughout Table of Contents l Harness C++’s strengths; avoid its dangers About the Author l Build more easily maintainable code Build more powerful, robust, maintainable C++ software! For developers with experience in any language, Victor Shtern’s Core C++ teaches C++ the right way: by applying the best software engineering practices and methodologies to programming in C++. Even if you’ve already worked with C++, this comprehensive book will show you how to build code that is more robust, far easier to maintain and modify, and far more valuable. Shtern’s book teaches object-oriented principles before teaching the language, helping you derive all the power of object-oriented development to build superior software. Learn how to make design decisions based on key criteria such as information hiding and pushing responsibilities from clients down to server classes. Then, master every key feature of ANSI/ISO C++ from a software engineer’s perspective: classes, methods, const modifiers, dynamic memory management, class composition, inheritance, polymorphism, I/O, and much more. If you want to build outstanding C++ software, coding skill isn’t enough. Objects aren’t enough. You must design, think, and program using today’s best software engineering practices -- and with Core C++, you will. So, Core C++ delivers: l The application of software engineering principles to C++ programming l A strong emphasis on writing code for easier future maintainance and modification l A practical understanding of object-oriented principles before teaching the language l Insight into the latest ANSI/ISO C++ features l Thorough explanations that respect your intelligence l Hundreds of realistic, to-the-point code examples l Levity Breaks: Stories and vignettes that illustrate key topics, concepts, and ideas through humor Every core series book: l Demonstrates practical techniques used by professional developers. file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm (1 of 1187) [8/17/2002 2:57:43 PM] file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm l Features robust, thoroughly tested sample code and realistic examples. l Focuses on the cutting-edge technologies you need to master today. l Provides expert advice that will help you build superior software. Table of Content Table of Content Preface How Is This Different from Other C++ Books? Who This Book Is For How This Book Is Organized Conventions Used in This Book Accessing the Source Code Feedback Acknowledgments Part I: Introduction to Programming with C++ Chapter 1. Object-oriented approach: What's So Good About It? The Origins of the Software Crisis Remedy 1: Eliminating Programmers Remedy 2: Improved Management Techniques Remedy 3: Designing a Complex and Verbose Language The Object-Oriented Approach: Are We Getting Something for Nothing? Characteristics of the C++ Programming Language Summary Chapter 2. Getting Started Quickly: A Brief Overview of C++ The Basic Program Structure Preprocessor Directives Comments Declarations and Definitions Statements and Expressions Functions and Function Calls Classes Dealing with Program Development Tools Summary Chapter 3. Working with C++ Data and Expressions Values and Their Types file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm (2 of 1187) [8/17/2002 2:57:44 PM] file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm Integral Types Floating Point Types Working with C++ Expressions Mixed Expressions: Hidden Dangers Summary Chapter 4. C++ Control Flow Statements and Expressions Conditional Statements Iteration C++ Jump Statements Summary Chapter 5. Aggregation with Programmer-Defined Data Types Arrays as Homogeneous Aggregates Structures as Heterogeneous Aggregates Unions, Enumerations, and Bit Fields Summary Chapter 6. Memory Management: the Stack and the Heap Name Scope as a Tool for Cooperation Memory Management: Storage Classes Memory Management: Using Heap Input and Output with Disk Files Summary Part II: Object-oriented programing with C++ Chapter 7. Programming With C++ Functions C++ Functions as Modularization Tools Argument Promotions and Conversions Parameter Passing in C++ Inline Functions Parameters with Default Values Function Name Overloading Summary Chapter 8. Object-Oriented Programming with Functions Cohesion Coupling Data Encapsulation Information Hiding A Larger Example of Encapsulation file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm (3 of 1187) [8/17/2002 2:57:44 PM] file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm Shortcomings of Encapsulation with Functions Summary Chapter 9. C++ Class as a Unit of Modularization Basic Class Syntax Binding Together Data and Operations Elimination of Name Conflicts Implementing Member Functions Outside of Class Defining Class Objects of Different Storage Classes Controlling Access to Class Members Initialization of Object Instances Constructors as Member Functions Default Constructors Copy Constructors Conversion Constructors Destructors Timing of Constructor and Destructor Invocations Class Scope and the Overriding of Names in Nested Scopes Memory Management with Operators and Function Calls Using Returned Objects in Client Code More on the Keyword const Static Class Members Summary Chapter 10. Operator Functions: Another Good idea Overloading of Operators Limitations on Operator Overloading Overloaded Operators as Class Members Case Study: Rational Numbers Mixed Types as Parameters Friend Functions Summary Chapter 11. Constructors and Destructors: Potential Trouble More on Passing Objects by Value Operator Overloading for Nonnumeric Classes More on the Copy Constructor Overloading the Assignment Operator Practical Considerations: What to Implement Summary file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm (4 of 1187) [8/17/2002 2:57:44 PM] file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm Part III: Object-Oriented Programming with Aggregation and Inheritance Chapter 12. Composite Classes: Pitfalls and Advantages Using Class Objects as Data Members Initialization of Composite Objects Data Members with Special Properties Container Classes Summary Chapter 13. Similar Classes: How to Treat Them Treating Similar Classes Syntax of C++ Inheritance Accessing Base and Derived Class Services Accessing Base Components of a Derived Class Object Scope Rules and Name Resolution Under Inheritance Constructors and Destructors for Derived Classes Summary Chapter 14. Choosing between Inheritance and Composition Choosing a Technique for Code Reuse Unified Modeling Language Case Study: A Rental Store On Class Visibility and Division of Responsibilities Summary Part IV: Advanced uses of C++ Chapter 15. Virtual Functions and other Advanced Uses of Inheritance Conversions Between Nonrelated Classes Conversions Between Classes Related Through Inheritance Virtual Functions: Yet Another New Idea Multiple Inheritance: Several Base Classes Summary Chapter 16. Advanced Uses of Operator Overloading Operator Overloading: A Brief Overview Unary Operators Subscript and Function Call Operators Input/Output Operators Summary Chapter 17. Templates: Yet Another Design Tool A Simple Example of a Class Design Reuse Syntax of Template Class Definition file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm (5 of 1187) [8/17/2002 2:57:44 PM] file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm Template Classes with Several Parameters Relations Between Instantiations of Template Classes Template Specializations Template Functions Summary Chapter 18. Programming with Exceptions A Simple Example of Exception Processing Syntax of C++ Exceptions Exceptions with Class Objects Type Cast Operators Summary Chapter 19. What We Have Learned C++ as a Traditional Programming Language C++ as a Modular Language C++ as an Object-Oriented Language C++ and Competition Summary Preface Congratulations! You have opened one of the most useful C++ books on the market! It will teach you the strengths and weaknesses of C++, and it will do this better than any other book I have seen. And I have seen a lot of C++ books. How Is This Different from Other C++ Books? Of course, any author can claim that his or her book is one of the best on the market. What sets this book apart is its software engineering and maintenance perspective on writing C++ code. Very few C++ books (if any) do that. Why is the software engineering and maintenance approach important? The point is that C++ changed not only the way we write computer programs, it also changed the way we learn programming languages. In the "good old days," you would spend a day or two looking at the basic syntax of the language, then you would try your hand at simple programming problems. Then you would learn more-complex syntax and would tackle more-complex problems. In a week or two (or in three or four weeks for a really complex language), you would have seen it "all" and could pose as an "expert." It's different with C++; a very large and very complex language. Granted, it is a superset of C, and file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm (6 of 1187) [8/17/2002 2:57:44 PM] file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm you can learn to write simple C programs (and, hence, C++ programs) very quickly. But things are different for complex programs. If the programmer does not know C++ well, a complex C++ program will not be portable; its code will be difficult to reuse, and it will be difficult to maintain. C++ is a great language¡Xit was created as a general-purpose engineering language, and its design is a clear success. Today, C++ is a language of choice for business, engineering, and even real-time applications. Significant effort was spent on the design of the language, to ensure that C++ programs provide great performance, that they support dynamic memory management, and that different parts of programs could be made relatively independent. Yet in all three areas, things can potentially go wrong even with a syntactically correct and thoroughly tested C++ program: 1. It can be slow¡Xmuch slower¡Xthan a comparable C program. 2. It can contain memory management errors that affect the program only when memory usage changes (e.g., another program is installed); these errors might crash the program or quietly produce incorrect results. 3. It can contain dependencies between different parts of the program so that the maintainer has a hard time understanding the intent of the designer; a poorly written C++ program can be harder to maintain and reuse than a non-object-oriented program. How important is this? If you are writing a small program that will be used only for a short time, then execution speed, memory management, maintainability, and reusability may not be of great importance. All that counts is your ability to quickly produce a solution. If this solution is not satisfactory, you can cut your losses by throwing the program away and writing another one. For this, any C++ book would do (but hey, you can still buy this one and enjoy its informal style and original insights into the language and its usage). However, if you are working in a group, creating large applications that cannot be easily discarded and will be maintained for a long time, everything matters. The software engineering and maintenance approach I am advancing in this book is very useful and quite unique. Most books on the market do not mention these issues at all. (Just check their indexes and see for yourself.) When they do, they fail to spell out the techniques that can remedy a tough situation. Another important characteristic of this book is its approach to the presentation of the material. There are many books on the market that do a good job enumerating the features of the language but do a mediocre job teaching you how to use the language. This is similar to learning a natural language. If you read a French grammar book, will it enable you to speak French? I did not study French, but I did study English, and I know¡Xreading grammar books does not help to develop language fluency. In this book, I will show you how to use and how not to use the language, especially from the point of view of reusability and future maintenance. file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm (7 of 1187) [8/17/2002 2:57:44 PM] file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm Another teaching issue is that C++ features are so intertwined that it is hard to present C++ in a linear fashion, from simple to more complex. Many C++ authors do not even try. They say that these efforts "offend the intelligence of the reader." As a result, they might mention in Chapter 3 a concept that is explained only in Chapter 8, leaving the reader intimidated and frustrated. My approach to teaching C++ is different. I introduce topics cyclically, first as a general overview and then again at a greater depth, with bells and whistles, and nowhere will your understanding depend on material in later chapters. I developed my approach through years of teaching working software professionals. At Boston University Metropolitan College, most of my students hold professional jobs and come to classes in the evening in search of professional growth. I also taught numerous professional development seminars and on-site training courses. I developed great empathy for the students and their struggle with language concepts and programming techniques, and I translated this experience into a well- thought-out sequence of topics, examples, counterexamples, and recommendations. I think that my approach to teaching C++ is fairly unique, and you will benefit from it. Who This Book Is For This book is written for professionals who are looking for a no-nonsense presentation of practical details combined with a deep understanding of C++ subtleties. This book is written for you if you are looking for practical details of new technologies with a thorough discussion of their use. It is written for you if you have experience in other languages and are moving to C++. If you are an experienced C++ programmer, you will find this book useful and sometimes an eye-opener. If this is your first programming book (and this is perfectly all right if it is), you will be well rewarded for the effort spent on reading it. How This Book Is Organized I decided not to follow other authors who give you a detailed tour of their books, explaining what is covered and where. Unfamiliar terms, concepts and techniques will not make much sense to you now and will probably be quite boring. This is why I put the summary of the book into its final chapter, Chapter 19, "What We Have Learned," and you can read it if you are interested. It makes more sense there. Instead, let me tell you what parts of the book might be of interest to you, depending on your background and experience. file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm (8 of 1187) [8/17/2002 2:57:44 PM] file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm ¡P If you are experienced in C++, Parts 3 and 4 will be most useful to you with their coverage of C++ power and programming pitfalls. If, in your initial study of C++, you were rushed to objects without building your muscle in procedural programming, memory management, and creating maintainable code, a review of Parts 1 and 2 will also be helpful (and interesting). ¡P If you are an experienced C programmer who wants to move on to C++, Parts 2, 3, and 4 are written for you. If you briefly review Part 1, you might find the discussion of C from the software engineering and maintenance perspective interesting. ¡P If you a programmer with experience in high-level languages other than C, C++, or Java, you should probably start with Part 1. ¡P If you are looking for an introduction to programming, you should skip Chapter 1, "Object-Oriented Approach: What's So Good About It?": It will be too abstract for you at this stage. Study the other chapters of Part 1 first, then go back to Chapter 1, and then continue with Parts 2, 3, and 4. Conventions Used in This Book All the code presented in the numbered listings in this book has been thoroughly debugged and tested using several compilers, including Microsoft Visual C++, Borland, and GNU compilers. This code can be run without any modifications. The code snippets outside of the listings have also been debugged and tested. They are runnable, but they require a harness to be run. Throughout the book, the code listings and snippets are presented in a monospace font. The same is true of C++ terms in the text of the book. If, for example, I am discussing a C++ class whose name is "Account," I will write it as the way it would be written in program code. When I talk Account, about private data members, I will use the regular font for the word "private" and the monospace font for the keyword private. Icons denote statements that are particularly useful or need your special attention. They are notes, tips, and alerts. NOTE This icon flags information that deserves special attention, such as an interesting fact about the topic at hand or one that the reader may want to keep in mind while programming. ALERT file://///Administrator/General%20English%20Learning/it2002-7-6/core.htm (9 of 1187) [8/17/2002 2:57:44 PM]

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.