dimanche 2 août 2020

Choose between two approaches to design user registration

Designing a cab-hailing service. The user components are as follows

User registration components

Flow 1 Driver registration API= register_driver(user_obj), This calls the RegisterUserService with an object of type driver. and this service calls the register method available on the User interface implementing object(driver). The RegisterUserService is concerned with all things user. whereas driver objects register method would be concerned with driver specific implementation of registration.

Flow 2 API : register_driver(driver_obj), This calls a service called RegisterDriverService with a driver object. This service calls the register method on an instance of driver class called register. Both, driver and rider have separate paths but can share common lib functions. for example : they can both use the same NameValidationService, PhoneNumberValidationService

The Pro of using Flow 1 : Any changes to the high level registration process can be handled easily. For example. after registration, a user gets a registration completion message. The message can be implemented in the user implementing object, but the call to it will be done in the user registration service, because the user registration service decides the high level flow of registration. Keeping the high level flow consistent would be difficult if driverregistration service and rider reg serv were separate and used common functions.

User level operations such as validating name & phone number can be generic and would be done in the user registration service.

creating such a pipeline, which has been tested up to a point, would allow easy addition of a new user type( for eg. admin). The adminUser class would simply know how to register and what should be its welcome message.

Pros of Flow 2

Allowing for separate registration services allows more flexibility to create own flows. for example: drivers need to have their drivers license authenticated, whereas riders don't have any documents which need authentication. Making it mandatory for a user to authenticate in the other flow would require the Rider class to implement an empty authenticate function, which could evolve to become a much bigger problem

Duplication will not much of a problem, as the common lib functions would allow both types of users to share and reuse. Lib functions could later become tough to delete though.

Higher Readability and lesser complexity: Given that the complete registration process is handled by a single Driver registration Service. Debugging any issues seem to be easier than Flow 1 Which would you choose?

alternatives

pros/cons

Aucun commentaire:

Enregistrer un commentaire