CS246 Lecture Notes - Lecture 18: Decorator Pattern, Unified Modeling Language
Document Summary
You have an existing object, you want to add some features/functionality to this object. Abswindow *w = new basicwindow(); w = new scroll (w); w = new menu(w); Uml diagram of the decorator pattern was taken by the phone camera. Do not use casting unless you really have to. Node n; int *p = (int *) &n; cout << *p << endl; // this might actually print data field depending on the compiler. // that is if the data field was presented first. If your compiler presented the nullptr first, this will terminate the program. [a template function is a function with a type paramater- the type you want to cast to] static_cast. This is known as a sensible cast - a cast where the conversion/meaning is well-defined. 2 void foo(int x) { } void foo(double x) { } 9 double a = //something; foo(a); // calls foo(double) // we want to call foo(int) using a foo(static_cast(a)); // calls foo(int)