Flutter

Flutter Design Patterns

Singleton, Factory, Repository, Dependency Injection, Service Locator, SOLID principles

24 คำถามสัมภาษณ์·
Senior
1

What is the Singleton pattern in Dart/Flutter?

คำตอบ

Singleton ensures a class has only one instance and provides a global access point to it. In Dart, it's typically implemented with a factory constructor and a private static instance. This pattern is useful for shared services like configurations or API clients.

2

How to correctly implement a Singleton in Dart using a factory constructor?

คำตอบ

The standard implementation uses a private static _instance, a private _internal() constructor, and a factory constructor that always returns _instance. This approach ensures only one instance exists and is thread-safe in Dart thanks to the single-threaded event loop.

3

What is the main disadvantage of the Singleton pattern in a Flutter application?

คำตอบ

Singleton creates global state that makes unit testing difficult because it's hard to mock or replace the instance. It also introduces tight coupling between classes and can hide actual dependencies, making code less maintainable and harder to refactor.

4

What is the Factory pattern in object-oriented programming?

5

What is the difference between Factory Method and Abstract Factory in Flutter?

+21 คำถามสัมภาษณ์

เชี่ยวชาญ Flutter สำหรับการสัมภาษณ์ครั้งถัดไป

เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์

เริ่มใช้ฟรี