Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional inheritance #117

Open
nikitinvv opened this issue Mar 28, 2021 · 1 comment
Open

Conditional inheritance #117

nikitinvv opened this issue Mar 28, 2021 · 1 comment

Comments

@nikitinvv
Copy link
Contributor

nikitinvv commented Mar 28, 2021

@MarkRivers @decarlof I see huge code duplication with the current inheritance scheme. For instance, we have 3 classes tomoscan2bm, tomoscan2bm_step, and tomoscan2b_stream inherited from tomoscan_pso, tomoscan_step, and tomoscan_stream, respectively. However, functionality of these inherited classes is very similar (or even just 100% copy). I suggest to employ dynamic conditional inheritance implemented like this:


class TomoscanPSO():
    def __init__(self):
        print(f'inheritance from class Pso')


class TomoscanSTEP():
    def __init__(self):
        print(f'inheritance from class Step')


class TomoscanStream():
    def __init__(self):
        print(f'inheritance from class Stream')

mdict = {'STEP': TomoscanSTEP,
         'PSO': TomoscanPSO,
         'STREAM': TomoscanStream
         }

def makeclass(type):
    class Tomoscan2BM(mdict[type]):
            def __init__(self):
                super().__init__()
                print(f'class 2BM')
    return Tomoscan2BM()


a = makeclass('STEP')

In this case, there will be only one class Tomoscan2BM instead of 3, variable 'type' can be taken from the command line.

@decarlof
Copy link
Member

@nikitinvv this is a good idea and will eliminate python code duplication but we need also to propagate the conditional inheritance to the IOC/medm screens. Now for example when we run the fly, step or stream we have customized IOC Pvs and associated medm screens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants