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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Prototype pattern: potential type mismatches #29

Open
horw opened this issue Oct 25, 2023 · 1 comment
Open

The Prototype pattern: potential type mismatches #29

horw opened this issue Oct 25, 2023 · 1 comment

Comments

@horw
Copy link

horw commented Oct 25, 2023

Hi, perhaps this example isn't the best one because there's a potential for type mismatches.
If we want to use type matching here, perhaps 'switch' is a better choice; or at least I think using the following type checking method would be better.

        t1, ok := c.(*Type1)
	if !ok {
		t.Fatal("error")
	}

https://github.com/senghoo/golang-design-pattern/blob/e9d687a5411f31db2a5d7229f94fb4c6c73163d3/07_prototype/prototype_test.go#L38C1-L38C18

@wulie
Copy link

wulie commented Oct 25, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants