Last active
August 7, 2018 02:21
-
-
Save pulkitkumar/cb55214a7cf2badc2da45d658dc2df34 to your computer and use it in GitHub Desktop.
OOP Semantics
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
package user | |
import ( | |
"io" | |
) | |
type User struct { | |
Name string | |
Email string | |
} | |
type UserRepository interface { | |
Read() ([]User, error) | |
Write([]User) error | |
} | |
type defaultUserRepository struct { | |
rdr io.Reader | |
wtr io.WriteCloser | |
} | |
func (u *defaultUserRepository) Read() ([]User, error) { | |
// read using reader u.rdr | |
//u.rdr.Read() | |
return []User{}, nil | |
} | |
func (u *defaultUserRepository) Write(usr []User) error { | |
// write using u.wtr | |
//u.wtr.Write(...) | |
return nil | |
} | |
func CreateUserRepository(r io.Reader, w io.WriteCloser) UserRepository { | |
repo := defaultUserRepository{ | |
rdr: r, | |
wtr: w, | |
} | |
return &repo | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment