Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m doing a small assignment in C++ where I have to use concepts like virtual f

ID: 642512 • Letter: I

Question

I'm doing a small assignment in C++ where I have to use concepts like virtual functions and inheritance in a domain of my choice. I'm implementing the prototype for a package manager in Linux.

I have the base class Package, this has attributes like package_id, name, version, dependencies etc. There are two types of packages MetaPackages and ConcretePackages which differ in the way they must be installed and removed.

I am thinking of declaring the methods install and remove in Package as virtual. While storing these packages in a datafile can I somehow know if the stored package is Meta or Concrete.

I'm not sure as to how I should best design this. Can anybody point me to a resource so that I can better learn this stuff.

We have Grady Booch in our curriculum and honestly it's a pain to read much less comprehend.

Explanation / Answer

I am thinking of declaring the methods install and remove in Package as virtual.

Sounds like a good idea.

While storing these packages in a datafile can I somehow know if the stored package is Meta or Concrete.

Why do you need to know it? The point of polymorphism (and probably of this specific exercise) is that the user of the object doesn't need to know its concrete type, just call its methods. If said methods adhere to the "contract" defined by the base interface, their implementation details aren't important for the caller.

You should implement the install and remove methods in each concrete subclass according to the specifities of meta and concrete packages. Then the installer of the packages needs only to iterate through the collection of packages and call the respective method on each.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote