在框架中解耦服务和模型

时间:2018-01-27 17:10:59

标签: java

在我的框架中,我有一个班级PhonecallerService。目前,我的框架的用户必须为他们想要呼叫的每个人创建一个新的PhonecallerService,因为该服务取决于PhonecallerCredentials。问题是,用户不应该调用PhonecallerService::callPhone方法。他们应该只定义一个状态,调用PhonecallerService::callPhone方法。

PhonecallerService

package framework
public class PhonecallerService{

    private PhonecallerCredentials phonecallerCredentials;

    public PhonecallerService(PhonecallerCredentials phonecallerCredentials){
        this.phonecallerCredentials = phonecallerCredentials;
    }

    public void callPhone(){
        // use phonecallerCredentials to call
    }
}

ClientClass

package client
public class ClientClass extends FrameworkClass{

    public Actions provideActions(Actions action){
        return action.put(STATE.ERROR, PhonecallerServiceFactory.create(new PhonecallerCredentials(x, y));
    }
}

有没有办法在下面创建一个真实的PhonecallerService?当我使用下面的方法时,我不知道如何在我的框架中获得PhonecallerCredentialsPhonecallerService之间的联系。

PhonecallerService

package framework
@Service
public class PhonecallerService{
    public void callPhone(PhonecallerCredentials phonecallerCredentials){
        // use phonecallerCredentials to call
    }
}

ClientClass

package client
public class ClientClass extends FrameworkClass{

    public Actions provideActions(Actions action){
        return action.put(STATE.ERROR, new PhonecallerCredentials(x, y);
    }
}

0 个答案:

没有答案