Middle
Fasad (Facade) nedir?
sobes.tech yapay zeka
AI'dan gelen yanıt
Fasade, bir alt sistemdeki bir dizi arayüze birleşik bir arayüz sağlayan yapısal tasarım desenidir. Bu, alt sistemin iç yapısına girmeden, onu kullanmayı kolaylaştıran yüksek seviyeli bir arayüz tanımlar.
Fasadenin temel amaçları:
- Basitleştirme: Alt sistemin karmaşıklığını basit bir arayüzle gizler.
- Bağlılığı azaltma: Müşteri kodu sadece fasad ile etkileşime girer, doğrudan alt sistem bileşenleriyle değil.
- Kapsülleme: Alt sistemin iç yapısındaki değişiklikler, fasadı kullanan müşteri kodunu daha az etkiler.
Kullanım örneği:
Bir online mağazada sipariş işleme sistemini düşünün; envanter, ödemeler, teslimat ve bildirim alt sistemlerini içerir. Müşteri, bu alt sistemlerin her birinin metodlarını ayrı ayrı çağırmak yerine, bir OrderProcessor fasad oluşturabilir.
// Fasad olmadan yapı örneği
// Müşteri kodu karmaşık hale gelir
// inventorySystem.checkStock(item);
// paymentSystem.processPayment(amount);
// shippingSystem.arrangeShipping(address);
// notificationSystem.sendConfirmation(email);
// Fasad ile yapı örneği
public class OrderProcessorFacade {
private InventorySystem inventorySystem;
private PaymentSystem paymentSystem;
private ShippingSystem shippingSystem;
private NotificationSystem notificationSystem;
public OrderProcessorFacade() {
this.inventorySystem = new InventorySystem();
this.paymentSystem = new PaymentSystem();
this.shippingSystem = new ShippingSystem();
this.notificationSystem = new NotificationSystem();
}
public void placeOrder(Item item, double amount, String address, String email) {
// Stok kontrolü
inventorySystem.checkStock(item);
// Ödeme işlemi
paymentSystem.processPayment(amount);
// Teslimat düzenlemesi
shippingSystem.arrangeShipping(address);
// Bildirim gönder
notificationSystem.sendConfirmation(email);
// Ek mantık veya hata yönetimi
}
}
// Müşteri kodu fasad kullanımıyla
// OrderProcessorFacade orderProcessor = new OrderProcessorFacade();
// orderProcessor.placeOrder(item, amount, address, email);
// Müşteri için etkileşim önemli ölçüde basitleştirilir