Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bujosa/adapter-design-pattern
See example of adapter design pattern in go
https://github.com/bujosa/adapter-design-pattern
adapter-pattern design-patterns go structural-patterns
Last synced: about 1 month ago
JSON representation
See example of adapter design pattern in go
- Host: GitHub
- URL: https://github.com/bujosa/adapter-design-pattern
- Owner: bujosa
- License: mit
- Created: 2024-01-29T21:47:08.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-01-29T22:00:04.000Z (11 months ago)
- Last Synced: 2024-06-20T22:26:12.554Z (7 months ago)
- Topics: adapter-pattern, design-patterns, go, structural-patterns
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# adapter-design-pattern
See example of adapter design pattern in go, this is a structural design pattern that allows two incompatible interfaces to work together.## Documentation
### NewPrinter Interface
NewPrinter is an interface that represents a new printer. It has a method PrintStored that returns a string.#### PrintStored Method
PrintStored is a method that prints the stored message. It returns the printed message as a string.### PrinterAdapter Struct
PrinterAdapter is a struct that represents an adapter for a printer. It contains an OldPrinter of type LegacyPrinter and a Msg of type string.#### OldPrinter
OldPrinter is a LegacyPrinter that represents the old printer.#### Msg
Msg is a string that represents the message to be printed.### PrintStored Method
PrintStored is a method of PrinterAdapter that prints the stored message using the adapter. It calls the Print method of the OldPrinter and appends "Adapter" to the returned message. The modified message is then printed to the console. If the OldPrinter is nil, no action is taken. The modified message is returned.