Answer the question
In order to leave comments, you need to log in
Convenient extension of class functionality
I write in Python. Faced such task — there is a class for operation with a database. It has some features. One gets the first 50 records, the second saves the record and returns some parameter, the third gets the record, and so on. To work, I create 1 instance of this class and set a reference to it in all objects, and they refer to this class by reference and thus gain access to its functions.
class DB():
def __init__(self):
#Какие-то настройки для создания соединения с БД
def createConnection(self):
#Создание соединения
self.connection = new Connection(param1, param2, param3)
def get50Records(self):
#Получение 50 записей
result = self.conncetion.select(TABLE_RECORDS, limit=50)
return result
def saveRecords(self, params):
pass
....
class DBget50Records():
def get50Records(self):
#Получение 50 записей
result = self.conncetion.select(TABLE_RECORDS, limit=50)
return result
class DBsaveRecords():
def saveRecords(self, params):
pass
class DB(DBget50Records, DBsaveRecords):
def __init__(self):
#Какие-то настройки для создания соединения с БД
def createConnection(self):
#Создание соединения
self.connection = new Connection(param1, param2, param3)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question