lundi 15 mai 2017

Is this an Stretegy Pattern implementation?

I have built a software architecture and now I wonder design pattern is this one:

All layers are composed of multiple interfaces that contain small pieces of logic:

HasService indicates that a class contains an EntityService implementation of some E and Q type.

public interface HasService<E extends BaseEntity, Q extends QueryParams> {
    EntityService<E, Q> getService();
}

InsertDtoEndpointindicates that a class has the ability to receive a json input formated as D, map it to E, insert it and then map it back to D before return it.

public interface InsertDtoEndpoint<E extends AbstractBaseEntity, D extends Dto, Q extends QueryParams>
    extends Endpoint, HasService<E, Q> {

    @POST
    default Response insert(D dto) {
        return ok(executeInsert(dto));
    }

    default D executeInsert(D dto) {
        E mapped = mapInsertRequestRecordToPersistentEntity(dto);
        return mapInsertResponseRecordToDto(getService().save(mapped));
    }

    E mapInsertRequestRecordToPersistentEntity(D dto);
    D mapInsertResponseRecordToDto(E entity);

}

Then the actual endpoints which are accessed via http calls are composed of a composition of these interfaces:

public class SomeEntityEndpoint implements InsertDtoEndpoint<SomeEntity, SomeDto, DefaultQueryParam>, FetchEndpoint<SomeEntity, DefaultQueryParams>, FindEndpoint<SomeEntity, DetailedDto, DefaultQueryParams> {

    SomeEntity mapInsertRequestRecordToPersistentEntity(SomeDto dto) { 
        //map to entity 
    }

    SomeDto mapInsertResponseRecordToDto(SomeEntity entity) {
        //map to dto
    }

    DetailedDto mapFindResponseRecordToDto(SomeEntity entity) {
        //Map to dto
    }

    getService() {
        //Return service..
    }

 }

How is the name of this pattern?

Aucun commentaire:

Enregistrer un commentaire