어제에 이은 class AdapterPay implements PaymentSystem 공부함_20260529

JAEWOONG LEE·2026년 5월 29일
post-thumbnail

Yesterday, I did not get it all part of process and source in detail.

I am trying to get them now and....

anyway, point is if, an adapter,an apikey and so on.

it's case of my tests.

and Next Mon, I will type down over and over again.

package oop4practice.eg25Delete;

interface PaymentSystem
{
void ProcessPay();
}

class NormalPay implements PaymentSystem
{
public void ProcessPay()
{
System.out.println("일반 결제 되었습니다.");
}
}

class AdapterPay implements PaymentSystem
{
PayPalAPI payPalAPI;
String apiKey;

AdapterPay(PayPalAPI payPalAPI, String apiKey)
{
    this.payPalAPI = payPalAPI;
    this.apiKey = apiKey;

}

public void ProcessPay()
{
    System.out.println("일반 결제 되었습니다.");
}

}

class PayPalAPI
{
public void handlePay(String apikey)
{
System.out.println(apikey+" Pal로 결제하겠습니다.");
}
}

class PayBrand
{
PaymentSystem paymentSystem;
PayPalAPI palAPI;

public PayBrand(PaymentSystem paymentSystem, PayPalAPI palAPI)
{
    this.paymentSystem = paymentSystem;
    this.palAPI = palAPI;
}

void ProcessOrder(String sPaymethod)    
{
   if("default-pay".equals(sPaymethod))
    {
        paymentSystem.ProcessPay(); // 여기서 기본 결제 처리 완료!
    }
    else if("paypal".equals(sPaymethod))
    {
        String apikey = "secret-123";
        palAPI.handlePay(apikey);  // 여기서 페이팔 결제 처리 완료!
    }
    else
    {
        System.out.println("알수 없는 결제 수단");
        return;
    }
}

}

public class Main
{
public static void main(String[] args)
{
String payRequest = "paypal";
String apikey = "secret-123";

    PaymentSystem paymentSystem;
    PayPalAPI payPalAPI = new PayPalAPI();

    paymentSystem = new AdapterPay(payPalAPI, apikey) ;

    PayBrand payBrand = new PayBrand(paymentSystem, payPalAPI);

    payBrand.ProcessOrder(payRequest);
}

}

profile
just for programming test

0개의 댓글