Greetings. There is a topic - Reference book owner video.

The base of video films: title, studio, genre, year of release, director, leading roles, summary, subjective assessment of the film. The fact of the presence of the film in the video library. Registration of issue and return of the cassette (this task already).

How to implement 5 classes on this topic (in C ++, OOP)?

OOP began to study and has already worked with classes, inheritance, constructors, etc., but the very logic to create exactly 5 classes with virtual inheritance that will interact with themselves is still difficult for me.

No need for code , please help with advice on the implementation of these 5 classes.

  • I advise: start with one! - Vladimir Martyanov
  • It is necessary exactly 5. One class will be responsible for the data, a kind of database, others will inherit its fields and methods. - gmastrbit
  • So start with one, with an ancestor. - Vladimir Martyanov

2 answers 2

Perhaps this refers to the use of a purely virtual film class, and from it to implement 4 classes of the heir? As an option, the movie class is purely virtual and contains only methods (a purely virtual destructor), and the heir classes already have fields and override methods. You will show polymorphism with this method by creating objects through a movie type pointer, as well as creating classes.

  • This is a good idea, but I cannot think of these heirs. - gmastrbit
  • The film is a parent, heirs: horror, comedy, fantasy, detective story. - Danya

For good, inheritance is not really necessary here - except that all films can be inherited from the same base class "film" in order to store films in an array (it is better to use std::vector<std::unique_ptr<Film>> for this std::vector<std::unique_ptr<Film>> in order to avoid problems with deleting objects, but for a lab this may be superfluous). You can inherit several classes from the film by genre, but they will differ only in the value of the “genre” field, in practice it is a bad idea to do so. But, apparently, this is what they demand from you.

Perhaps this idea will pass: declare a virtual method std::string getDescription() in the base Film class (return the description), and in descendants implement a different format of the return value depending on the genre (interchange the order of displaying fields, for example).

Where to push virtual inheritance - I can not even imagine. It is generally not recommended to use.