0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

コード設計学習8 悪しき構造をクラス設計で封じる

Posted at

このブログについて

最近システム設計に興味を持ち、特にコード設計について学んだことをまとめます。
自分の今後の戒めも込めて。

悪しき構造について

命名が曖昧、ネストが深い、データクラスだらけ。
こうした“悪魔”は、健全なクラス設計で退治できます。

悪いコード例

if (user != null && user.IsActive && !user.IsLocked)
{
    SendMail(user.Email);
}

良いコード例

if (user.CanReceiveMail())
{
    SendMail(user.Email);
}

条件をCanReceiveMail()というメソッドに閉じ込めるだけで、ネストが消え、構造がシンプルになります。
クラス設計とは悪魔退治の最前線です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?