Architechture 2

 



package practice3.abstracts;

import practice2.entity.Customer;

public interface CustomerService {
void save(Customer customer);
}
package practice3.abstracts;

import practice2.entity.Customer;

public interface CustomerCheckService {
boolean checkIfRealPerson(Customer customer);
}
package practice3.abstracts;

import practice2.entity.Customer;

public abstract class BaseCustomerManager implements CustomerService{
@Override
public void save(Customer customer) {
System.out.println("Saved in db: " + customer.getName());
}
}
package practice3.adapter;

import practice2.entity.Customer;
import practice3.abstracts.CustomerCheckService;

public class MernisServiceAdapter implements CustomerCheckService {
@Override
public boolean checkIfRealPerson(Customer customer) {
return true;
}
}
package practice3.concretes;

import practice2.entity.Customer;
import practice3.abstracts.CustomerCheckService;

public class CustomerCheckManager implements CustomerCheckService {
@Override
public boolean checkIfRealPerson(Customer customer) {
return true;
}
}
package practice3.concretes;

import practice2.entity.Customer;
import practice3.abstracts.BaseCustomerManager;
import practice3.abstracts.CustomerCheckService;

public class NeroCustomerManager extends BaseCustomerManager {
private CustomerCheckService customerCheckService;

public NeroCustomerManager(CustomerCheckService customerCheckService){
this.customerCheckService = customerCheckService;
}

@Override
public void save(Customer customer) {
if(customerCheckService.checkIfRealPerson(customer)){
super.save(customer);
} else {
System.out.println("Not a valid person");
}
}
}
package practice3.concretes;

import practice2.entity.Customer;
import practice3.abstracts.BaseCustomerManager;
import practice3.abstracts.CustomerCheckService;

public class StarbucksCustomerManager extends BaseCustomerManager {
private CustomerCheckService customerCheckService;

public StarbucksCustomerManager(CustomerCheckService customerCheckService) {
this.customerCheckService = customerCheckService;
}

@Override
public void save(Customer customer) {
if (customerCheckService.checkIfRealPerson(customer)) {
super.save(customer);
} else {
System.out.println("Not a valid person");
}
}
}
package practice3.entities;


public class Customer {
private int id;
private String name;
private String surname;
private String nationality;

public Customer() {
}

public Customer(int id, String name, String surname, String nationality) {
this.id = id;
this.name = name;
this.surname = surname;
this.nationality = nationality;
}

public int getId() {
return id;
}

public Customer setId(int id) {
this.id = id;
return this;
}

public String getName() {
return name;
}

public Customer setName(String name) {
this.name = name;
return this;
}

public String getSurname() {
return surname;
}

public Customer setSurname(String surname) {
this.surname = surname;
return this;
}

public String getNationality() {
return nationality;
}

public Customer setNationality(String nationality) {
this.nationality = nationality;
return this;
}
}

Комментарии

Популярные сообщения из этого блога

Lesson1: JDK, JVM, JRE

SE_21_Lesson_11: Inheritance, Polymorphism

SE_21_Lesson_9: Initialization Blocks, Wrapper types, String class