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

推荐订阅源

博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
博客园_首页
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
罗磊的独立博客
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
B
Blog
D
Docker
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
MyScale Blog
MyScale Blog
G
Google Developers Blog
博客园 - 司徒正美
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
M
MIT News - Artificial intelligence
Recent Announcements
Recent Announcements

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
Singleton
Yusuf Aytas · 2010-01-10 · via Yusuf Aytas

Published · 1 min read

Bu yazımda size Singleton adındaki nesneye dayalı yazılım şablonunu(Object-Oriented Design Pattern) anlatacağım. Singleton benim en çok kullandığım dizayn şablonlarından biri. Bu şablonu genelde yaratmak istediğiniz objeden yalnız bir tane olmasını istediğiniz durumlarda kullanırız . Örnek vericek olursak, bir oyun yazıyorsunuz ve bu oyununun GameEngine(Oyun Motoru) adında oyunu çekip çeviren bir sınıfı var ve birden fazla oyun motoru olmasını istemiyorsunuz. Bu GameEngine sınıfını singleton yapıyoruz ve bu nesneden birden fazla yaratılmasını engelliyoruz.

public class Singleton{
	private static Singleton singleton;
	private Singleton(){}
	public Singleton getInstance(){
		if(singleton==null)
			return (singleton = new Singleton());
		return singleton;
	}
}