今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Factory pattern example
- [Instructor] Let's actually implement a factory pattern example in go code. So for this example, we're going to implement a factory that creates two kinds of objects that are both types of publications, newspapers, and magazines. So here in the editor, let's open up the publication.go file. This file defines the ipublication interface, which has a set of methods for setting various pieces of data on a publication type, which is defined as the publication struct right here. So there's a name, the number of pages and the name of the publisher. So if we scroll down below that we can see that the publication struct implements the ipublication interface methods for setting and getting various fields. So that's pretty straightforward. So now let's go look at the magazine and newspaper.go files. The code in these files implement the magazine and newspaper types, which basically just embed the publication type. So…
内容
-
-
-
-
(已锁定)
Builder pattern overview1 分钟 52 秒
-
(已锁定)
Builder pattern example9 分钟 58 秒
-
(已锁定)
Factory pattern overview1 分钟 40 秒
-
(已锁定)
Factory pattern example6 分钟 12 秒
-
(已锁定)
Singleton pattern overview2 分钟 10 秒
-
(已锁定)
Basic Singleton pattern example3 分钟 17 秒
-
(已锁定)
Making Singleton concurrent-safe3 分钟 44 秒
-
(已锁定)
-
-
-