lundi 26 juillet 2021

When to use strategy or facade?

So me and my group is working on this real estate program (school assignment), we are troubled if we used misused Strategy pattern, and should use Facade instead. I am writing codes for CRUD of database, I used Strategy pattern to call those CRUD methods (add,delete,update) from the jform. We are still starting to learn different design patterns, so we would like to as help if this is a correct implementation.

This is my code for Strategy Pattern

public interface methods {
    public void doOperation(int id, String type, int area, String address, String listingStatus);
}

public class methodUse {
    private methods method;

    public methodUse(methods method) {
        this.method = method;
    }
    
    public void executeMethod(int id, String type, int area, String address, String listingStatus){
         method.doOperation(id, type, area, address, listingStatus);
    }
}

public class methodUpdate implements methods{
    private SystemAdmin systemAdmin = new SystemAdmin();

    @Override
    public void doOperation(int id, String type, int area, String address, String listingStatus) {
        systemAdmin.updatePropertyListing(id, listingStatus);
    
    }
}

public class methodDelete implements methods{
   private SystemAdmin systemAdmin = new SystemAdmin();


    @Override
    public void doOperation(int id, String type, int area, String address, String listingStatus) {
      systemAdmin.deleteListing(id);
    }
}

public class methodAdd implements methods{
    private SystemAdmin systemAdmin = new SystemAdmin();

    @Override
    public void doOperation(int id, String type, int area, String address, String listingStatus) {
        systemAdmin.addListing(id, type, area, address, listingStatus);
    }
    
}

The classes are called on the jform every time the specific button is clicked, ex. add button executes strategy add.

I would like to ask you all if what we did was the right implementation of Strategy pattern.

Aucun commentaire:

Enregistrer un commentaire