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

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

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