mercredi 24 novembre 2021

Is there an object-oriented alternative to the Front Controller Pattern?

Okay, so i stumbled upon the Front Controller Pattern, and as far as i know from web frameworks like Spring Web (Java) or Flask (Python), they all embody this Design Pattern, leading to code such as (sample Spring Web):

@PreAuthorize("hasAnyAuthority('ROLE_USER','ROLE_ADMIN','ROLE_SYSADMIN')")
@GetMapping(value = "/path/to/{id}/somewhere")
public void doIt(@PathVariable("id") String id)
{
    // ...
}

@PostMapping(value = "/path/to/{id}/somewhere")
@PreAuthorize("hasAnyAuthority('ROLE_ADMIN','ROLE_SYSADMIN')")
public SomeDto doSomething(@PathVariable("id") String id)
{
    // ...
}

@GetMapping(value = "/api/agb/check")
@PreAuthorize("hasAnyAuthority('ROLE_USER','ROLE_ADMIN','ROLE_SYSADMIN')")
public SomeDto doSomeotherthing()
{
    // ...
}

@GetMapping(value = "/api/agb")
@PreAuthorize("hasAnyAuthority('ROLE_ADMIN','ROLE_SYSADMIN')")
public List<SomeDto> getAll()
{
    // ...
}

The "advantage" of this pattern is the centralized control flow, is said. But, isn´t it the case that object-oriented design is about distributing responsibilities and therefore getting rid of such centralized control flow?

Is there a more object-oriented design alternative to the front controller pattern when handling web requests?

Aucun commentaire:

Enregistrer un commentaire