Tesla 两个毛子 难出天际的面试

吐血了

 

public class Account{

  String id;
  String name;
  List<Address> addresses;

}

public class Address{

  String street;
  String city;
  String country;
  AddressType type;

}

public enum AddressType {

    BILLING, MAILING, REGISTRATION, PACKAGE_MAILING;

}

public class Service implements ServiceInterface{

    @Override
  public void doSomething(Account account){    
      //...
      sendPackageProcess(account);
    //...
  }

    @Override
  public void doSomethingElse(Account account){
      //..
        sendPackageProcess(account);
    //..
  }
      @Override
  public void sendPackageProcess(Account account) {
            boolean isQualified = false;
    // check if account has at least one mailing address
    for (Address address: account.addresses) {
            if(address.type.equals(AddressType.PACKAGE_MAILING))
            isQualified = true;
          break;
    }
        
    if (isQualified)
        sendPackage();
  }



}






public class Service2 implements ServiceInterface{
    @Override
  public void doSomething(Account account){    
      //...
      sendPackageProcess(account);
    //...
  }

    @Override
  public void doSomethingElse(Account account){
      //..
        sendPackageProcess(account);
    //..
  }
  
  @Override
  public void sendPackageProcess(Account account) {
            boolean isQualified = false;
    // check if account has at least one mailing address
    for (Address address: account.addresses) {
            if(address.type.equals(AddressType.PACKAGE_MAILING))
            isQualified = true;
          break;
    }
        
    if (isQualified)
        sendPackage();
  }

public interface ServiceInterface {
    public void doSomething();
  
  public void doSomethingElse();
  
  public void sendPackageProcess(Account account);

}

abstract class Service {
    abstract void doSomething();
  
  abstract void doSomethingElse();
  
  public void sendPackageProcess(Account account) {
            boolean isQualified = false;
    // check if account has at least one mailing address
    for (Address address: account.addresses) {
            if(address.type.equals(AddressType.PACKAGE_MAILING))
            isQualified = true;
          break;
    }
        
    if (isQualified)
        sendPackage();
  }
}

 Service1 = new 

}

 

posted @ 2022-10-15 06:35  苗妙苗  阅读(33)  评论(0编辑  收藏  举报