algorithm - general programming issue on classes -
let's want create movie database software.
i need class actor have attribute name, surname, dob, awards, , should have array of "movie" object.
i need class movie, have attribute title, duration, year, should have array of "actor" object. represent cast of movie.
actor object need list of movie done actor, movie object need list of actors played in it. gets quite messy cause it's class containing 1 , viceversa, compiler stuck.
which right way represent situation?
in languages concept same. you've observed, can't have "lists of movie objects" embedded in actors , vice versa, instead keep list of each , "reference" other objects in way. might using unique reference value (e.g. incrementing number) can used search other list or associative container (e.g. use key/value "std::map" in c++ rather linked list), or keeping reference or (weak) pointer directly logically linked objects....
Comments
Post a Comment