Почему ошибка компиляции в Customerervice service = serviceFactory.getInstance (). GetServiceType (ServiceType.customer)JAVA

Программисты JAVA общаются здесь
Anonymous
Почему ошибка компиляции в Customerervice service = serviceFactory.getInstance (). GetServiceType (ServiceType.customer)

Сообщение Anonymous »

SuperService: < /p>

Код: Выделить всё

package service;

public interface SuperService {
}
< /code>
Customer service: < /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) {

}
}
Это многоуровневый дизайн архитектуры, и здесь я попытался использовать шаблон проектирования заводской разработки для передачи объекта CustomerserviceImpl от уровня обслуживания к уровню контроллера/презентации. Я пытался понять ограниченные дженерики типа и решил провести эксперимент, чтобы понять концепцию, тогда только я столкнулся с проблемой. Можете ли вы помочь мне понять, почему нет ошибки компиляции в Customerervice service = serviceFactory.getInstance (). GetServiceType (serviceType.customer); Поскольку Customerervice

Подробнее здесь: https://stackoverflow.com/questions/794 ... instance-g

Вернуться в «JAVA»