forked from senghoo/golang-design-pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
25 additions
and
32 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,24 @@ | ||
package abstractfactory | ||
|
||
import "testing" | ||
|
||
func getMainAndDetail(factory DAOFactory) (string, string) { | ||
main := factory.CreateOrderMainDAO() | ||
detail := factory.CreateOrderDetailDAO() | ||
return main.SaveOrderMain(), detail.SaveOrderDetail() | ||
func getMainAndDetail(factory DAOFactory) { | ||
factory.CreateOrderMainDAO().SaveOrderMain() | ||
factory.CreateOrderDetailDAO().SaveOrderDetail() | ||
} | ||
|
||
func TestRdbFactory(t *testing.T) { | ||
func ExampleRdbFactory() { | ||
var factory DAOFactory | ||
factory = &RDBDAOFactory{} | ||
main, detail := getMainAndDetail(factory) | ||
if main != "rdb main save" { | ||
t.Fatal("main save fail") | ||
} | ||
if detail != "rdb detail save" { | ||
t.Fatal("detail save fail") | ||
} | ||
getMainAndDetail(factory) | ||
// Output: | ||
// rdb main save | ||
// rdb detail save | ||
} | ||
|
||
func TestXmlFactory(t *testing.T) { | ||
func ExampleXmlFactory() { | ||
var factory DAOFactory | ||
factory = &XMLDAOFactory{} | ||
main, detail := getMainAndDetail(factory) | ||
if main != "xml main save" { | ||
t.Fatal("main save fail") | ||
} | ||
if detail != "xml detail save" { | ||
t.Fatal("detail save fail") | ||
} | ||
getMainAndDetail(factory) | ||
// Output: | ||
// xml main save | ||
// xml detail save | ||
} |