1

我有一个关于设计模式的问题。我怎么知道哪种设计模式对某些模块有用?

我正在创建一个视频会议系统,其中对于数据库连接,我在数据库的同一时间为一个实例使用了单例设计模式。

现在,我正在为我必须遵循的设计模式创建聊天和视频(一对多)会议模块。

我应该为此声明哪些类和接口。

Class Database
Class Chat
Class TextChat Extends Chat
Class VideoChat Extends Chat

这是声明模块的正确方法吗?

4

1 回答 1

1

Design patterns: each design pattern solves some problem. You need to describe the problem you have and find a matching design pattern. sourcemaking.com/design_patterns

What Singleton gives you is lazy loading of some instance and the constructor. So, you can load it based on some parameters. If multiple threads access your instance you need to synchronize them. In a static access you don't worry about loading of anything and you just pass what you need to get a DB resource. You can code DB access as number of patterns but DB access ok to be simple static stuff that any threads can access to call the data.

Database Access: The best way to access data is through static rather than instance methods. Singleton is instance, a single instance designed for different solutions than database access.

Video conferencing software: Are you developing Lync or Skype, etc...? Why wouldn't you just use a professionally done software for that, most of which is free?

于 2013-09-26T16:52:10.690 回答