Below is a class dictionary and the corresponding C++ class interface. Find the unknowns. A = B. B : C | D | A *common* W. W ~ {DemIdent}. C = . D = . class B : public Construction { private: W* w; static const char* type; public: B( W* = NULL ); W* get_w() const { return( w ); } void set_w( W* new_w ) { w = new_w; } W* rset_w( W* ); const char* get_type() const { return( type ); } #include "B.h" }; class A : public B { private: B* b; static const char* type; public: A( B* = NULL ); B* get_b() const { return( b ); } void set_b( B* new_b ) { b = new_b; } B* rset_b( B* ); const char* get_type() const { return( type ); } #include "A.h" }; typedef DemIdent* DemIdent_; declare(list,DemIdent_); class W : public DemIdent_list_ { private: static const char* type; public: W( DemIdent* first ) : DemIdent_list_( first ) { /* empty */ }; W() { /* empty */ }; const char* get_type() const { return ( type ); } #include "W.h" }; class C : public B { private: static const char* type; public: C(); const char* get_type() const { return( type ); } #include "C.h" }; class D : public B { private: static const char* type; public: D(); const char* get_type() const { return( type ); } #include "D.h" }; A = "a" B. B : C | D | A *common* W. W ~ "(" {DemIdent} ")". C = "c". D = "d". Consider the following three legal A-objects a1, a2, a3. Find the unknowns. A-object a1: : A ( < b > : C ( < w > : W { } ) < w > : W { } ) A-object a2: : A ( < b > : A ( < b > : A ( < b > : C ( < w > : W { } ) < w > : W { } ) < w > : W { } ) < w > : W { } ) A-object a3: : A ( < b > : A ( < b > : D ( < w > : W { : DemIdent "x" } ) < w > : W { : DemIdent "x" , : DemIdent "y" , : DemIdent "z" } ) < w > : W { : DemIdent "z" } ) } ) For A-object a1 above, write C++ statements which create that object. Find the unknowns below. C* c1 = new C(); c1 -> set_w(new W()); A* a1 = new A (c1); a1 -> set_w(new W()); // : A ( // < b > : C ( // < w > : W { } ) // < w > : W { } ) , Consider the following illegal objects. Find the first error A-object i1: first error is on line UNKNOWN: replace letter UNKNOWN by UNKNOWN : A ( < b > : A ( < b > : D ( < b > : C ( < w > : W { } ) < w > : W { } ) < w > : V { } ) < v > : W { } ) A-object i1: first error is on line UNKNOWN: UNKNOWN is missing. : A ( < b > : A ( < b > : D // ( // < w > : W { // : DemIdent "x" } ) < w > : W { : DemIdent "x" , : DemIdent "y" , : DemIdent "z" } ) < w > : W { : DemIdent "z" } ) } ) C *operation* void fun() *traverse* *from* A *via* D *to* F *wrapper* F *prefix* (@ cout << "in F " << endl; @) *wrapper* A *suffix* (@ cout << "after A-traversal " << endl; @) A = B F. B = C F. C = D F. D = E. E = F. F = . // A = B // F . void A::fun( ) { // outgoing calls this->get_b()->fun( ); // suffix class wrappers cout << "after A-traversal " << endl; } // B = C // F . void B::fun( ) { // outgoing calls this->get_c()->fun( ); } // C = D // F . void C::fun( ) { // outgoing calls this->get_d()->fun( ); } // D = E . void D::fun( ) { // outgoing calls this->get_e()->fun( ); } // E = F . void E::fun( ) { // outgoing calls this->get_f()->fun( ); } // F = . void F::fun( ) { // prefix class wrappers cout << "in F " << endl; } A = B1 F. B1 = C1. C1 = B. B = C F. C = D F. D = E1 F. E1 = F1. F1 = E. E = F. F = . // A = B1 // F . void A::fun( ) { // construction edge prefix wrappers this->get_b1()->fun( ); // suffix class wrappers cout << "after A-traversal " << endl; } // B1 = C1 . void B1::fun( ) { // outgoing calls this->get_c1()->fun( ); } // C1 = B . void C1::fun( ) { // outgoing calls this->get_b()->fun( ); } // B = C // F . void B::fun( ) { // construction edge prefix wrappers this->get_c()->fun( ); } // C = D // F . void C::fun( ) { // outgoing calls this->get_d()->fun( ); } // D = E1 // F . void D::fun( ) { // outgoing calls this->get_e1()->fun( ); this->get_f4()->fun( ); } // E1 = F1 . void E1::fun( ) { // outgoing calls this->get_f5()->fun( ); } // F1 = E . void F1::fun( ) { // outgoing calls this->get_e()->fun( ); } // E = F . void E::fun( ) { // outgoing calls this->get_f()->fun( ); } // F = . void F::fun( ) { // prefix class wrappers cout << "in F " << endl; } Rewrite the following programs so that they satisfy the Law of Demeter. ======================================================== // violating the Law of Demeter // A = P1. void A::f1(A* a, B* b) { this -> get_p1() -> get_p2() -> r(a,b); } // satisfying the Law of Demeter // A = P1. void A::f1(A* a, B* b) { this -> get_p1() -> f1(a,b); } // P1 = P2. void P1::f1(A* a, B* b) { this -> get_p2() -> r(a,b); } ======================================================== ======================================================== // violating the Law of Demeter // A = P1. void A::f1(A* a, B* b, C* c, D* d) { this -> get_p1() -> r(a,b) -> s(c,d); } // satisfying the Law of Demeter // A = P1. void A::f1(A* a, B* b, C* c, D* d) { this -> f1(this -> get_p1() -> r(a,b), c, d); } // A = P1. void A::f1(R* r, C* c, D* d) { r -> s(c,d); } ========================================================