Created
May 30, 2020 13:53
-
-
Save ankur22/01c5b0d1e2940b50c28059580d41d03d to your computer and use it in GitHub Desktop.
Example of struct embedding where there's two functions with same name, so we override that function
This file contains 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
type logger struct{} | |
func (l *logger) do(in string) { | |
if l.validate(in) { | |
log.Println(in) | |
} | |
} | |
func (l *logger) validate(in string) bool { | |
if len(in) == 0 { | |
return false | |
} | |
return true | |
} | |
type checker struct{} | |
func (c *checker) validate(in string) bool { | |
if len(in) == 0 { | |
return false | |
} | |
return true | |
} | |
type loggerAndChecker struct { | |
*logger | |
*checker | |
} | |
func (l *loggerAndChecker) validate(in string) bool { | |
return l.logger.validate(in) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment