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

推荐订阅源

N
Netflix TechBlog - Medium
月光博客
月光博客
Y
Y Combinator Blog
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
美团技术团队
T
Tailwind CSS Blog
小众软件
小众软件
量子位
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
有赞技术团队
有赞技术团队
P
Proofpoint News Feed
G
Google Developers Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Recent Announcements
Recent Announcements
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More

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!");
	}
}