惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
WordPress大学
WordPress大学
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
博客园 - Franky
D
Docker
小众软件
小众软件
阮一峰的网络日志
阮一峰的网络日志
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
U
Unit 42
M
MIT News - Artificial intelligence
B
Blog
GbyAI
GbyAI
C
Check Point Blog
P
Proofpoint News Feed
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
IT之家
IT之家
Google DeepMind News
Google DeepMind News
V
V2EX
Stack Overflow Blog
Stack Overflow Blog

Yusuf Aytas

When Code Is Cheap, Does Quality Still Matter? Why Crouching Tiger, Hidden Dragon Is a Masterpiece Why We Ignore Advice The Mirror Is Part of the Machine When Too Many Maps Overlap on One Person The Work Runs on Different Maps Your Work Introduces You Trial By Fire The Dude Why Headcount Math Lies Capacity Is the Roadmap The Roadmap Is Not the System Torres del Paine W Trek Escaping Status Theater Incentives Drive Everything Scaling Culture Without Dilution What Good Looks Like Why Airport Security Feels Random Why Politics Appear How to Work with Me The Janus Protocol Multi-Horizon Delivery Framework What Good Execution Looks Like Managing Your Manager Why Kingdom of Heaven’s Director’s Cut Is Better AI Broke Interviews Most of What We Call Progress Managers Have Been Vibe Coding All Along Stop Wasting Brainpower Why Over-Engineering Happens
Adapter
Yusuf Aytas · 2010-01-10 · via Yusuf Aytas

Published · 1 min read

Bu yazımda size Adapter adında nesneye dayalı yazılım şablonunu (Object-Oriented Design Pattern) anlatacağım. Bu yazılım şablonu genellikle daha önce yazılan bir kodun başka bir programa entegre olmasını sağlamak amaçlı yapılır. Aslında adından da anlaşılacağı üzere adaptör özelliğine sahiptir. Bir program yazacağız ve bir arayüz sınıfına ihtiyacımız var.Bu kodun başka biri tarafından yazıldığını ve bu koddan yararlanabileceğimizi gördük.  Ama Şöyle bir sıkıntı oluştu, bizim yazdığınız ara yüze(interface) bulduğunuz kod uyumlu değil. Biz bu noktada hemen araya bir adaptör sınıfı yazıyoruz. Bu iki nesneyi biri birine uyumlu hale getiriyorsunuz. Aşağıda verdiğim şema, şablonu daha anlamlı hale getiricektir.

Adapter tasarım deseni şemasıAdapter tasarım deseni şeması

public class User{
	public static void main(String \[\] args){
		Adapter a = new Adapter();
		a.doThis();
	}
}
public interface Target{
	public void doThis();
}
public class Adapter extends Adaptee implements Target{
	public void doThis(){
		super.doThat();
	}
}
public class Adaptee{
	public void doThat(){
		System.out.println("Hello world!");
	}
}