Created
January 27, 2023 09:31
-
-
Save arriqaaq/3300ce1274d58bfa4c52bf435f372a00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type LegacyPrinter struct { | |
} | |
func (l *LegacyPrinter) Print(s string) { | |
fmt.Println(s) | |
} | |
type Printer interface { | |
PrintStored() string | |
} | |
type PrinterAdapter struct { | |
LegacyPrinter | |
} | |
func (p *PrinterAdapter) PrintStored() string { | |
return "Adapted" | |
} | |
func main() { | |
adapter := &PrinterAdapter{} | |
fmt.Println(adapter.PrintStored()) | |
adapter.Print("Hello World!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment