lundi 30 mars 2015

What's the design pattern here (if it is one)?

I would like to know if the following code represents any of the known design patterns. I'm doubtfully wondering if it applies to the Proxy pattern. The point is that in the system B (who implements the interfaces), I can call the Alaskan or Russian bear repositories directly, but in most cases the generic repository (BearRemoteRepository) would be called. Beyond the above question I'm wondering if this is a good practice, to have opened the possibility of using two different interfaces, even if they have the same methods of its parent. Important! The two bears have different behaviours...



//System A:
public interface IBearRepository {

public Bear save(Bear pBear);

}


public interface IBearAlaskaRepository extends IBearRepository {

}

public interface IBearRussiaRepository extends IBearRepository {

}


//System B:
public class BearRemoteRepository implements IBearRepository {

IBearRepository bearAlaskaRemoteRepository;
IBearRepository bearRussiaRemoteRepository;

@Override
Bear save(Bear pBear) {
ICompromissoRepository remoteRepository = resolveRepository(pBear)
return remoteRepository.save(pBear);
}

private IBearRepository resolveRepository(Bear pBear) {
if (pBear in BearAlaska) {
return bearAlaskaRemoteRepository;
} else {
return bearRussiaRemoteRepository;
}
}
}

public class BearAlaskaRemoteRepository implements IBearAlaskaRepository {

@Override
Bear save(Bear pBear) {
return save(pBear);
}

}

public class BearRussiaRemoteRepository implements IBearRussiaRepository {

@Override
Bear save(Bear pBear) {
return save(pBear);
}

}

Aucun commentaire:

Enregistrer un commentaire