Here is part of my code:
class classA(Something):
CONFIG={
"opt_a": "opt_b"
}
def construct(self):
Some Unique Code
.
.
.
.
Some Common Code
class classB(Something):
CONFIG={
"opt_a": "opt_b"
}
def construct(self):
Some Unique Code
.
.
.
.
Some Common Code
The Some Common Code part is over 200 lines and it is exactly the same in both classA and classB. I have to create 5 or more such classes. This will result in a lot of duplication.
Update:
The Some Common Code parts consists of a lot of loops and other functions that rely on data from Some Unique Code.
Update after Raphael's Solution:
There are some common variables in classA and classB. These variables are used both inside the "common code" as well as the "unique code". Moving them from one class to another creates variable undefined errors.
Here is my code after updates:
class Something(Else):
CONFIG = {
"alpha": "beta"
}
def setup(self):
// Some Code
return self
def common_method(self):
for i in texts:
// Manipulates Boxes
class classA(Something):
CONFIG={
"opt_a": "opt_b"
}
def construct(self):
texts = []
texts.append('Apple')
.
.
.
.
self.common_method()
class classB(Something):
CONFIG={
"opt_a": "opt_b"
}
def construct(self):
texts = []
texts.append('Mango')
.
.
.
.
self.common_method()
I am new to Python so I don't know how I can avoid this duplication. Any help would be appreciated.
Thanks.
forloops and other methods of theSomethingclass. Will this be a problem?