Khác biệt Static Class vs Singleton Instance trong C#
Static Class
- Static là keyword
- Static classes chỉ chứa static members
- Static objects lưu trong stack
- Static không thể implement interfaces, inherit từ classes khác
Singleton
- Singleton là design pattern
- Singleton là object creational pattern với một instance của class
- Singleton có thể implement interfaces, inherit từ classes khác, tuân thủ OOP concepts
- Singleton object có thể pass as reference
- Singleton hỗ trợ object disposal
- Singleton object lưu trên heap
- Singleton objects có thể cloned
- Singleton objects stored in Heap