Go

Go Design Patterns

Singleton, Factory, Builder, Strategy, Decorator, Adapter, functional options, SOLID

24 mülakat soruları·
Senior
1

What is the main advantage of the Functional Options pattern in Go?

Cevap

The Functional Options pattern allows creating configurable APIs with optional parameters without overloading constructors. It avoids multiple constructors with different signatures and provides an extensible and readable API. This pattern is idiomatic in Go because it leverages first-class functions and avoids ambiguous default values.

2

What approach is recommended for implementing the Singleton pattern in Go?

Cevap

In Go, the Singleton pattern is ideally implemented with sync.Once which guarantees thread-safe and lazy initialization. This approach avoids manual mutexes and double-checked locking which are error-prone. sync.Once ensures that a function is executed only once even with multiple concurrent goroutines.

3

Which SOLID principle encourages the use of interfaces in Go?

Cevap

The Dependency Inversion principle states that high-level modules should not depend on low-level modules, but on abstractions (interfaces). In Go, this translates to accepting interfaces and returning concrete types. This principle facilitates testing (mocking), decoupling and code maintainability.

4

How to implement the Factory pattern in Go idiomatically?

5

What is the main role of the Adapter pattern?

+21 mülakat soruları

Bir sonraki mülakatın için Go'de uzmanlaş

Tüm sorulara, flashcards'a, teknik testlere, code review alıştırmalarına ve mülakat simülatörlerine eriş.

Ücretsiz başla