c++ - Methods belonging to multiple classes -


i making small project extension of larger body of work. part of larger project there class contains number of methods. use of these methods methods in new class feel there must better way duplicating code different class name! there way make method belong multiple classes (i should mention of c++)! cheers, jack

there speaking 2 possibilities:

  • inheritance: if new class (b) , class you're interested in (a) represent is a relationship.

  • composition: add class you're interested in (a) field in new class (b). can use methods.

if class has more methods need, violates single responsibility principle, , should split it. if b have methods same name a, consider introducing interface methods common both classes (in general this+composition seems better solution inheritance).


Comments

Popular posts from this blog

javascript - How to name a jQuery function to make a browser's back button work? -

python - Django-easy-pdf: xhtml2pdf reporting reportlab 2.2+ is required, but 3.0 installed -

collision detection - C++ library for mesh to mesh intersection: what is available? -