1Nơi lắp ghép tạo new ShippingService(new SmsOrderNotifier(smsGateway)). ShippingService chỉ giữ field kiểu OrderNotifier nên không tự chọn kênh gửi.The wiring code creates new ShippingService(new SmsOrderNotifier(smsGateway)). ShippingService only holds an OrderNotifier field, so it never picks the channel itself.
2Đơn DH1001 được bàn giao cho shipper: markShipped() gọi notifier.orderShipped("0909123456", "DH1001"). Quy trình thông báo thuộc về OrderNotifier.Order DH1001 is handed to the shipper: markShipped() calls notifier.orderShipped("0909123456", "DH1001"). The notification workflow belongs to OrderNotifier.
3orderShipped() gọi createNotifier() thay vì viết cứng new. Đa hình đưa lời gọi tới bản override của SmsOrderNotifier, và nó trả về new SmsNotifier(gateway) dưới kiểu Notifier.orderShipped() calls createNotifier() instead of hard-coding new. Dynamic dispatch reaches SmsOrderNotifier's override, which returns new SmsNotifier(gateway) typed as Notifier.
4OrderNotifier ghép nội dung có mã DH1001 rồi gọi send() qua interface Notifier. Object thật là SmsNotifier nên nó gọi gateway.sendSms().OrderNotifier builds the message with DH1001 and calls send() through the Notifier interface. The real object is SmsNotifier, so it calls gateway.sendSms().
5Giờ khách VIP cần Zalo OA. Nơi lắp ghép tạo new ShippingService(new ZaloOrderNotifier(zaloClient)); ShippingService và orderShipped() không đổi một dòng nào.Now VIP customers need Zalo OA. The wiring code creates new ShippingService(new ZaloOrderNotifier(zaloClient)); ShippingService and orderShipped() don't change a single line.
6Đơn DH1002 được giao: markShipped() vẫn gọi đúng orderShipped("0912000111", "DH1002") như trước, cùng một quy trình final của OrderNotifier.Order DH1002 ships: markShipped() calls the same orderShipped("0912000111", "DH1002") as before, the same final workflow in OrderNotifier.
7Lần này createNotifier() rơi vào bản override của ZaloOrderNotifier, nên nó trả về new ZaloNotifier(zalo). Đây là chỗ duy nhất hai nhánh khác nhau.This time createNotifier() dispatches to ZaloOrderNotifier's override, which returns new ZaloNotifier(zalo). This is the only point where the two branches differ.
8send() vẫn được gọi qua Notifier, nhưng object thật là ZaloNotifier nên nó gọi zalo.pushOaMessage(). Bản Go in ra dòng tương ứng từ zaloNotifier.Send().send() is still called through Notifier, but the real object is ZaloNotifier, so it calls zalo.pushOaMessage(). The Go version prints the matching line from zaloNotifier.Send().
9Tổng kết: hai lần chạy dùng chung orderShipped() và hợp đồng Notifier; chỉ Creator con (SmsOrderNotifier hay ZaloOrderNotifier) quyết định Product nào được tạo. Trong Go, field NewNotifier đóng vai createNotifier().Summary: both runs share orderShipped() and the Notifier contract; only the concrete Creator (SmsOrderNotifier or ZaloOrderNotifier) decides which Product is built. In Go, the NewNotifier field plays the role of createNotifier().