データを提供する API に変更を加えています。一部の検索では、作成者に関するデータが必要で、IAuthor
オブジェクトが取得されます。API には、インターフェースと、と呼ばれるIAuthor
を実装する単一の具象クラスがあります。IAuthor
Author
IsNovelist
すべてではなく一部の検索のセマンティクスを変更するブール型プロパティを追加する必要があります。
オープン/クローズの原則について聞いたことがありますが、 IAuthor
and/orクラスを変更するとAuthor
これに違反するようです。では、この単純な変更を行うにはどうすればよいでしょうか。
アップデート:
間違ったクラスに集中していたのかもしれません。クラスに動作を追加したくありませんAuthor
(これは、パラメーターを API に渡す方法にすぎません)。したがって、Decorated
作成者はブール値フラグを必要としません。これはisNovelist == true
、暗示によるものだからです。
GetBooks
小説家としてフラグが立てられている著者を指定して、メソッドの動作を変更する必要があります。Books
このようなものですが、クラスを変更している (拡張していない) ため、私の考えはおそらく不安定です。
//Before
class Books
{
public Books[] GetBooks(IAuthor author){
// Call data access GetBooks...
}
}
//After
class Books
{
public Books[] GetBooks(IAuthor author){
// To maintain pre-existing behaviour
// call data access GetBooks with SQL param @isNovelist = false...
// (or don't pass anything because the SQL param defaults to false)
}
public Books[] GetBooksForNovelist(IAuthor author){
// To get new behaviour
// call data access GetBooks with SQL param @isNovelist = true
}
}