Misused design patterns

前端 未结 15 1494
故里飘歌
故里飘歌 2021-02-01 19:54

Are there, in the canonical Gang of Four list, any design patterns that you often find misused, misunderstood or overused (other than the highly debated Singleton)? In other wor

15条回答
  •  太阳男子
    2021-02-01 20:38

    You can't have straight answer for this question. It's mostly subjective and depends on application requirement.

    1. Most of the people quoted that Singleton_pattern is bad but it's not bad for every user and project. For my project requirement, it serves the purpose. I need one ConnectionManager to handle session management between Client and Application and Singleton does the job brilliantly.

    2. You have given a third party jar with good documentation. The jar contains inheritance hierarchy. Now you have to add a operation on each child. Since you don't have source code, you can't do it. Now you can benefit by using Visitor_pattern. But if you have source code with you, you may not use Visitor pattern at all. You can simple add new operation in parent and each child. Lack of source code does not imply that I am misusingVisitor pattern.

    3. I want to limit communication between various objects. I will go-ahead with implement Mediator_pattern for object communication. I want to limit the client exposure to my system to hide the complexity. I will go-ahead with Facade_pattern. That does not mean that I am Misusing these patterns. This same example can be extended to other patterns like Proxy_pattern etc.

提交回复
热议问题