Warum kein Kompilierfehler bei Customerservice Service = ServiceFactory.getInstance (). GetServicetype (servicetype.custJava

Java-Forum
Anonymous
 Warum kein Kompilierfehler bei Customerservice Service = ServiceFactory.getInstance (). GetServicetype (servicetype.cust

Post by Anonymous »

superservice: < /p>

Code: Select all

package service;

public interface SuperService {
}
< /code>
Customerservice: < /p>
package service.custom;

import dto.Customer;

import java.util.List;

public interface CustomerService{
boolean add(Customer customer);
Customer search(String id);
boolean update(String id, Customer customer);
boolean delete(String id);
List getAll();
}
< /code>
customerserviceImpl: < /p>
package service.custom.impl;

import dto.Customer;

public class CustomerServiceImpl{
public boolean add(Customer customer) {
return false;
}
}
< /code>
serviceFactory: < /p>
package service;

import service.custom.impl.CustomerServiceImpl;
import service.custom.impl.ItemServiceImpl;
import service.custom.impl.OrderServiceImpl;
import util.ServiceType;

public class ServiceFactory {
private static ServiceFactory instance;

private ServiceFactory(){

}

public static ServiceFactory getInstance(){
if(instance==null){
instance= new ServiceFactory();
}
return instance;
}

public  T getServiceType(ServiceType type){
switch (type){
case CUSTOMER:return (T) new CustomerServiceImpl();
case ITEM:return (T) new ItemServiceImpl();
case ORDER:return (T) new OrderServiceImpl();
}
return null;
}
}
< /code>
CustomerFormController: < /p>
package controller;

import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXTextField;
import dto.Customer;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import service.ServiceFactory;
import service.custom.CustomerService;
import util.ServiceType;

public class CustomerFormController {

@FXML
private JFXButton btnAdd;

@FXML
private JFXButton btnDelete;

@FXML
private JFXButton btnReload;

@FXML
private JFXButton btnSearch;

@FXML
private JFXButton btnUpdate;

@FXML
private TableColumn colAddress;

@FXML
private TableColumn colId;

@FXML
private TableColumn colName;

@FXML
private TableColumn colSalary;

@FXML
private TableView tblCustomers;

@FXML
private JFXTextField txtAddress;

@FXML
private JFXTextField txtId;

@FXML
private JFXTextField txtName;

@FXML
private JFXTextField txtSalary;

@FXML
void btnAddOnAction(ActionEvent event) {
String idText = txtId.getText();
String nameText = txtName.getText();
String addressText = txtAddress.getText();
double salary = Double.parseDouble(txtSalary.getText());

Customer customer = new Customer(idText, nameText, addressText, salary);
CustomerService service = ServiceFactory.getInstance().getServiceType(ServiceType.CUSTOMER);
service.add(customer);
}

@FXML
void btnDeleteOnAction(ActionEvent event) {

}

@FXML
void btnReloadOnAction(ActionEvent event) {

}

@FXML
void btnSearchOnAction(ActionEvent event) {

}

@FXML
void btnUpdateOnAction(ActionEvent event) {

}
}
Dies ist ein geschichteter Architektur -Design. Hier habe ich versucht, das Werksdesign -Muster zu verwenden, um ein CustomerserviceImpl -Objekt aus der Serviceebene an die Controller/Präsentationsschicht zu übergeben. Ich versuchte, begrenzte Generika zu verstehen, und beschloss, ein Experiment durchzuführen, um das Konzept zu verstehen, dann bin ich nur auf das Problem gestoßen. Können Sie mir helfen zu verstehen Implementiert Customerservice sollte der Compile nicht verstehen, dass ein Customerservice Referenz nicht für ein CustomerserviceImpl Objekt verwendet werden kann?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post