「More C++ Idioms/多態的例外(Polymorphic Exception)」の版間の差分
削除された内容 追加された内容
7 行
=== Motivation ===
[http://en.wikipedia.org/wiki/Dependency_inversion_principle Dependency Inversion Principle (DIP)], a popular object-oriented software design guideline states that higher level modules should not depend directly on lower level modules. Instead, both should depend on common abstractions (captured in the form of well-defined interfaces). For example, an object of type ''Person'' (say John) should not create and use an object of type ''HondaCivic'' but instead John should simply commit to a ''Car''
However, there are several places where DIP is violated: (1) using the Singleton pattern and (2) throwing exceptions! Singleton pattern breaks DIP because it forces the use of the concrete class name while accessing the static ''instance()'' function. A singleton should be passed as a parameter while calling a function or a constructor. A similar situation arises while dealing with exceptions in C++. The ''throw'' clause in C++ requires a concrete type name (class) to raise an exception. For example,
|