简体   繁体   中英

Design Patterns - What pattern is this?

Lets say I have the following structure in java:

@MappedSuperClass
public class User extends AbstractEntity { ... }

@Entity
public class SuperUser extends User { ... }

@Entity
public class RegularUser extends User { ... }

This project is structured in RESTful endpoints with 3 layers (Resources, Services and Repositories) with generic abstractions:

public class AbstractRepository<T extends AbstractEntity> { ... }

now I want to have some DB methods executed over all types of User , so I created this Repository layer:

public class UserRepository extends AbstractRepository<User> { ... }

Can it be called an Adapter or maybe Bridge, since its executing logic that kinda encapsulate the funcionality of two other classes ( RegularUserRepository and SuperUserRepository )?

There is no Gang-of-Four Design Pattern here. There are two kinds of polymorphism.

  1. Subtype Polymorphism - due to the inheritance relationship between User and its child classes.
  2. Parametric Polymorphism - due to the generic relationship between AbstractRepository and AbstractEntity .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM