Class design (execute different methods according to different types)

problem description

there are two types of users in a system, platform and enterprise (which may be increased later). No matter what type of users, the operations involved are additions, deletions, queries and changes, but different types of users may have different operation logic (mainly because the data used is different). At present, we want to use two categories to cover this part. For example, both platforms and enterprises have a common class A, which is done by adding, deleting, querying and changing. Then the class of the platform is a subclass of class A, and in the platform, it is not the addition, deletion, query and change of the platform, but the addition, deletion, query and change of the platform, that is, the name of the method has to be distinguished. The corporate approach is similar. The other is a super administrator, which requires the operation of the platform and the enterprise.

the environmental background of the problems and what methods you have tried

CRUD {
+ insert
+ update
+ delete
+ select
}

AccessCRUD extends CRUD {
+ beforeInsert
+ prepareInsert
+ postInsert
+ AfterInsert
...
}

OrganizeCRUD extends AccessCRUD {
+ platformBeforeInsert
+ platformPrepareInsert
+ platformPostInsert
+ platformAfterInsert
+ enterpriseBeforeInsert
+ enterprisePrepareInsert
+ enterprisePostInsert
+ enterpriseAfterInsert
}

what result do you expect? What is the error message actually seen?

there are too many methods in OrganizeCURD this way. It is expected that PlatformCRUD, EnterpriseCRUD, and then OrganizeCRUD inherits PlatformCRUD and EnterpriseCRUD to have methods to manipulate PlatformCRUD and EnterpriseCRUD. In addition, CRUD methods hope to be invisible in PlatformCRUD, EnterpriseCRUD and OrganizeCRUD

Jul.22,2021

complex logic should be disassembled.
yours are best written separately according to different roles. After that, it is easy to change and debug.

Menu