#π OOP multiple class inheritance.
18 messages Β· Page 1 of 1 (latest)
@sick jacinth
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
you probably, almost certainly shouldn't be doing that
if you describe your 20 classes then we can most likely come up with a better solution
I think so too. But i didn't write project from the beginning. They have written automation process with modules of the website. And every object is one job. After they must be used for different roles. Which leads to massive inheritance. So i am kinda bamboozled
Any ideas?
some form of adapter based pattern sounds appropriate for this imo
Hard to imagine it. Can you give a sample?
After a research i saw rocketchat doing something
Let me find it again
from rocketchat_API.APISections.assets import RocketChatAssets
from rocketchat_API.APISections.banners import RocketChatBanners
from rocketchat_API.APISections.channels import RocketChatChannels
from rocketchat_API.APISections.chat import RocketChatChat
from rocketchat_API.APISections.groups import RocketChatGroups
from rocketchat_API.APISections.im import RocketChatIM
from rocketchat_API.APISections.integrations import RocketChatIntegrations
from rocketchat_API.APISections.invites import RocketChatInvites
from rocketchat_API.APISections.livechat import RocketChatLivechat
from rocketchat_API.APISections.miscellaneous import RocketChatMiscellaneous
from rocketchat_API.APISections.permissions import RocketChatPermissions
from rocketchat_API.APISections.roles import RocketChatRoles
from rocketchat_API.APISections.rooms import RocketChatRooms
from rocketchat_API.APISections.settings import RocketChatSettings
from rocketchat_API.APISections.statistics import RocketChatStatistics
from rocketchat_API.APISections.subscriptions import RocketChatSubscriptions
from rocketchat_API.APISections.teams import RocketChatTeams
from rocketchat_API.APISections.users import RocketChatUsers
from rocketchat_API.APISections.video_conferences import RocketChatVideConferences
class RocketChat(
RocketChatUsers,
RocketChatChat,
RocketChatChannels,
RocketChatGroups,
RocketChatIM,
RocketChatIntegrations,
RocketChatStatistics,
RocketChatMiscellaneous,
RocketChatSettings,
RocketChatRooms,
RocketChatSubscriptions,
RocketChatAssets,
RocketChatPermissions,
RocketChatInvites,
RocketChatVideConferences,
RocketChatLivechat,
RocketChatTeams,
RocketChatRoles,
RocketChatBanners,
):
I don't know this is the best practice so i wrote here maybe some senior can give an advice
Job is like user can always do some patterns, role is like user, maintainer, admin, customer. Something like this. Like customer do job_1, job2, user do job_1, job_3. Kinda alghorithm
Why not just
from pprint import pprint
from rocketchat_API.rocketchat import RocketChat
proxy_dict = {
"http" : "http://127.0.0.1:3128",
"https" : "https://127.0.0.1:3128",
}
rocket = RocketChat('user', 'pass', server_url='https://demo.rocket.chat', proxies=proxy_dict)
pprint(rocket.me().json())
Because one user(role) can do 20 jobs
- If the behavior of these classes does not rely on state, then why not just either convert it into functions or instantiate a new instance whenever it's needed.
- If only one job is necessary for each instance of RocketChat, then you can just provide one job
- If you're not providing any data in the objects, why not just instantiate the objects when they are needed. You could even possibly provide needed data into the RocketChat constructor (which is especially relevant if the data in all of those jobs are similar)
- If neither of those options above works for you you can always store a dictionary with all of the jobs. Probably a good idea to use enumerations for that. Really not the best solution though
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.