Reputation: 25
I have an interface as shown below
public interface ATMbusinessRule {
public Map<String, List<ATM>> exceute(String pobCode, String plientlogo)
throws BuisnessRuleException;
}
I have two different classes as shown below, the first one
public class MaestroCardBusinessZZNFRuleImpl implements ATMbusinessRule {
public Map<String, List<ATM>> exceute(String pobCode, String ClientId)
throws BuisnessRuleException {
}
}
and the second class is shown as
public class MaestroCardBusinessXXNFRuleImpl implements ATMbusinessRule {
public Map<String, List<ATM>> exceute(String pobCode, String plientlogo)
throws BuisnessRuleException {
}
}
I want to change this design as what I am planning to write a simple class which will contain two different methods and the caller class will directly call these two methods and get the return value but i am thinking where the interface will fit in this criteria.
Please let me know which other design criteria will be the best
Upvotes: 0
Views: 59
Reputation:
Here is an example if, for some reason, you want to keep the interface. Then it could be of great help to extend it. I'll show you how. Please not, that I corrected your misspelling of "execute", "clientLogo" and "Business".
Interface
public interface ATMbusinessRule {
public Map<String, List<ATM>> execute(String pobCode, String ClientId, String clientLogo) throws BusinessRuleException;
}
Class
public class MaestroCardBusinessRuleImpl implements ATMbusinessRule {
public Map<String, List<ATM>> executeRule(String pobCode, String clientId, String clientLogo) throws BuisnessRuleException {
if(clientId != null) {
executeZZNRule(String pobCode, String clientId);
} else {
executeXXNFRule(String pobCode, String clientLogo);
}
}
private Map<String, List<ATM>> executeZZNRule(String pobCode, String clientId) throws BuisnessRuleException {
// concrete ZZN implementation here
}
private Map<String, List<ATM>> executeXXNFRule(String pobCode, String clientLogo) throws BuisnessRuleException {
// concrete XXNF implementation here
}
}
Now you just need to call
maestroCardBusinessRuleImpl.execute(pobCode, clientId, null);
or
maestroCardBusinessRuleImpl.execute(pobCode, null, clientLogo);
Upvotes: 0
Reputation: 33
The basic purpose of an Interface is to expose your methods without exposing their implementation to the calling code (If this is what you are looking to do here). Now depending on how many methods you want to expose, you can put that many methods in the interface, and have as many implementations of them as you want.
If that is not what you intend, and you want to have a simple concrete class which you can or want to expose to the calling code, there is no need of an interface. Just simply write your class in that case, without implementing any interface.
Upvotes: 0
Reputation: 653
Why not use one class without interface...
public class MaestroCardBusiness {
public Map<String, List<ATM>> exceuteZZNFRule(String pobCode, String ClientId)
throws BuisnessRuleException {
}
public Map<String, List<ATM>> exceuteXXNFRule(String pobCode, String plientlogo)
throws BuisnessRuleException {
}
}
If you want interface, then it wouldn't be possible to have one class with 2 method implementations that differ only by its parameter list. The code you already have is OK. But if you insist on having a single class, then the above code suffices.
Upvotes: 1