Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Prototype Pattern 馃帀 #5

Open
wants to merge 1 commit into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to鈥
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -0,0 +1,16 @@
package patterns

// Node interface
type Node interface {
Clone() Node
}

// File struct
type File struct {
Name string
}

// Clone method on File struct
func (f *File) Clone() Node {
return &File{Name: f.Name}
}
@@ -0,0 +1,19 @@
package patterns

import "testing"

func TestClone(t *testing.T) {
fileOriginal := &File{Name: "original"}

fileClone := fileOriginal.Clone()

fileCloneRaw, ok := fileClone.(*File)
if !ok {
t.Fatal("Type assertion for fileClone couldn't be done successfully")
}

fileOriginal.Name = "something awesome"
if fileCloneRaw.Name == fileOriginal.Name {
t.Error("fileOriginal cannot be equal to fileClone")
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can鈥檛 perform that action at this time.