Summary of CSCI 2210 (CS 271)
This page is being heavily edited…
OOP
- always remember: it is object oriented programming, not class oriented programming
- a class is simply our code template for a kind of object; it defines a new abstract data type
- always think about objects when programming
- objects do not exist “in your code” but rather exist when your program is running
- objects are living things that have attributes (data) and capabilities (methods), and have a lifetime
- static class members violate OOP (but can be useful in limited forms, for modularity)
- OOP involves encapsulation, inheritance, and polymorphism
- encapsulation: data and methods in class, plus ability to declare private data and methods
- inheritance: reusing functionality by implicit inclusion (subclass and base or super class); subclasses can override behavior if the base class declares the methods virtual
- polymorphism (subtype): “run-time” selection of proper behavior for type (dynamic resolution of virtual functions in classes)
- function/method overloading is also known as ad-hoc polymorphism
- C++ templates (and Java generics) are known as parametric polymorphism
- getter and setter methods violate good encapsulation and should be avoided (even though many people use them anyway!)
- inheritance is powerful and should be used carefully – always obey the Liskov Substitution Principle: an object of a subclass must be usable whereever an object of the base class can be used
- interfaces (explicit in Java but implicit in C++) and interface inheritance is often a better choice than implementation inheritance; keep interfaces small and focused, and make lots of them
Plain C
- functions and procedures (unique names)
- global and local variables (also static)
- I/O using printf() and scanf() – not typesafe!
- data representation limits (ranges, also accuracy for FP)
- pointers!
- malloc() and free() – not typesafe
- structs and linked structures
- macros and conditional compilation (#define, #ifdef..#endif)
- using C effectively requires using the C Standard Library effectively
C++
- function overloading (same name but unique parameter lists)
- default arguments
- new and delete (and array forms) – typesafe
- iostreams (partially covered) – typesafe
- classes and OOP!
Needs more editing below here…
Design, Tools, and UML
- file layout - header files, source files
- C++: one header and one source file per class (use #ifdef in header file)
- compilation and linking process: compiling to executable or to object code
- public and private - all data private
- refactoring
- testing
- noun/verb analysis of problem description
- UML class diagrams
- make
- gdb
- building a library
C++ vs. Java
- C++ has programmer-managed memory - i.e., new and delete.
- Java has garbage collection - i.e., only new, no delete.
- C++ has multiple inheritance - a class can have more than 1 base class
- Java has single inheritance (one base class) plus interfaces
- A C++ pure virtual base class is like a Java interface - no method implementations or data members, just method interface declarations
- C++ allows non-OO features – plain C functions, global data, etc.
- Java only has classes and objects – even main() must be in a class
- Both allow static class methods and data
- C++ has operator overloading. Java does not (although is discussed)
- C++ has templates. Java does not (but will someday).