Should make concrete factories in the same count of families of objects or according to stages in my problem?

I am programming a game. In this game I have 3 stages. In the first stage, there is a static goal and a static shooter in the game. In the second stage, the goal will move. And in the third one both are moving.

I want to use abstract factory to create objects of same family.

I want to know which of the following designs is right:

With 2 factories:

with 2 factories

With 3 factories:

with 3 factories

I just don’t know whether I should make concrete factories in the same count of families at the right hand or according to my problem?

For example, in the scenario, I have two families of objects (Products). First family is Gun and the second is Goal. But I have 3 stages that I have explained above. Is it right to have 2 factories because of the count of families of products or to have 3 families according to the stages?

6

To be honest, I’d probably take a different approach entirely. I’d build 4 factories, one for each object type. I’d then create a new Level class that contains one instance of a GunFactory and one of a GoalFactory, and I would create 3 instances of Level (probably stored in a List) each having the appropriate combination of factory.

There are two reasons for this, one theoretical and one practical. On a theoretical level, it is not at all clear that the responsibilities “create a gun” and “create a goal” are part of the same responsibility, so the Single Responsibility Pattern states that we should avoid having a single object that doesboth. The Level object on the other hand does have one clear responsibility: “hold together all of the information and behavior necessary to initialize a level of the game”.

The second, more practical aspect, is that this lets you add new levels more easily than either of your original suggestions. Say you want to add a fourth level that uses a different combination of gun and goal again; in your first design you would have to change your existing initialization code to pick a different set of factories, in the second you’d have to create a new subclass of your abstract factory class, whereas with my suggestion you’d just add a new Level instance to the list, a single line change. (This could also be phrased theoretically as “the design is more compliant with the open/closed principle when levels need to be added”, but I prefer the practical emphasis here).

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Should make concrete factories in the same count of families of objects or according to stages in my problem?

I am programming a game. In this game I have 3 stages. In the first stage, there is a static goal and a static shooter in the game. In the second stage, the goal will move. And in the third one both are moving.

I want to use abstract factory to create objects of same family.

I want to know which of the following designs is right:

With 2 factories:

with 2 factories

With 3 factories:

with 3 factories

I just don’t know whether I should make concrete factories in the same count of families at the right hand or according to my problem?

For example, in the scenario, I have two families of objects (Products). First family is Gun and the second is Goal. But I have 3 stages that I have explained above. Is it right to have 2 factories because of the count of families of products or to have 3 families according to the stages?

6

To be honest, I’d probably take a different approach entirely. I’d build 4 factories, one for each object type. I’d then create a new Level class that contains one instance of a GunFactory and one of a GoalFactory, and I would create 3 instances of Level (probably stored in a List) each having the appropriate combination of factory.

There are two reasons for this, one theoretical and one practical. On a theoretical level, it is not at all clear that the responsibilities “create a gun” and “create a goal” are part of the same responsibility, so the Single Responsibility Pattern states that we should avoid having a single object that doesboth. The Level object on the other hand does have one clear responsibility: “hold together all of the information and behavior necessary to initialize a level of the game”.

The second, more practical aspect, is that this lets you add new levels more easily than either of your original suggestions. Say you want to add a fourth level that uses a different combination of gun and goal again; in your first design you would have to change your existing initialization code to pick a different set of factories, in the second you’d have to create a new subclass of your abstract factory class, whereas with my suggestion you’d just add a new Level instance to the list, a single line change. (This could also be phrased theoretically as “the design is more compliant with the open/closed principle when levels need to be added”, but I prefer the practical emphasis here).

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật