Answer a d object has two different a sub objects one

Info icon This preview shows pages 7–9. Sign up to view the full content.

View Full Document Right Arrow Icon
other possible behavior. Answer: A D object has two different A sub-objects. One inside its B sub-object, and one inside its C sub-object. It is possible to arrange the inheritance hierarchy for D such that it only has one A sub-object. Such an inheritance is called virtual inheritance and must be specified at B and C (class B: public virtual A) since B and C objects have to be laid out differently to support virtual inheritance. 7
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Question 5: OO Design and STL Part A (5 points): For each statement, indicate true or false. false Methods should be noun-like. false Changing a good design to accomodate different features should be a massive undertaking: new changes are best redesigned from the ground up. false The “monolithic” design pattern is useful for minimizing the cognitive load on a code maintainer. false Computer scientists should seek to special case as many things as possible. false Design patterns are only useful in C++. Part B (8 points): The C++ STL vector class has no method to remove a particular el- ement from the vector. The STL provides a different means of removing a specific element. Briefly explain how this is accomplished. Answer: The vector class does not have a remove method, however, objects can be removed via iterators. The STL provides a remove alogirhtm which operates on any iterator so that it can be used with many different types of containers. 8
Image of page 8
Part C (7 points): Name the design pattern shown below: class A { virtual X* makeX() = 0; virtual Y* makeY() = 0; }; class OneThing : public A { virtual X* makeX() { return new XOne(); } virtual Y* makeY() { return new YOne(); } }; .... A* a = new OneThing(); ..... X * x = a->makeX(); ... Answer: This design pattern is called Abstract Factory. 9
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern