vendredi 23 août 2019

different return type and signature in Strategy Pattern in Java

I am bit confuse to use Strategy Pattern in my below case.

I have Contact class which is below.

public class Contact {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(columnDefinition = "INTEGER(11) UNSIGNED")
    private long id;

    @Column(columnDefinition = "INTEGER(11) UNSIGNED", nullable = false)
    private long userId;

    @Column(columnDefinition = "VARCHAR(255)")
    String firstname;

    @Column(columnDefinition = "VARCHAR(255)")
    String lastname;
// other fields

I have below scenario that

  1. getContact(long user_id) which accepts user_id as parameter and return List which have same user_id from database.
  2. updateContact(Contact contact) which accepts Contact as parameter and update this contact in database.
  3. deleteContact(long contactID) which accepts ContactID as parameter and delete this contact in database.
  4. addContact(Contact contact) which accepts Contact as parameter and add this contact in database.

    Strategy Pattern with Java with above requirement. I can use Strategy Pattern in Java if method has similar input parameter and similar output parameter. But for my case I have different input parameter and different output parameter so I am confuse that how can I use Strategy Pattern. Please guide me on this case.

Aucun commentaire:

Enregistrer un commentaire