かずきのBlog

C#やJavaやRubyとメモ書き

目次

Blog 利用状況

ニュース

わんくまBlogが不安定になったため、前に書いてたはてなダイアリーにメインを移動します。
かずきのBlog@Hatena
技術的なネタは、こちらにも、はてなへのリンクという形で掲載しますが、雑多ネタははてなダイアリーだけに掲載することが多いと思います。
コメント
プログラマ的自己紹介
お気に入りのツール/IDE
プロフィール
経歴
広告
アクセサリ

書庫

日記カテゴリ

オブジェクト指向で開発?

OOPだと、データと処理を1まとめに!!という記述を良く見る。
でも、私がプログラムを組むときは1まとめにしたりしてない…。

たとえば、従業員がいたとする。

class Employees {
  private int baseSalary;
  // そのたモロモロ
}

従業員の給与計算をしなきゃならないといわれたらOOPの教科書では↓みたいにEmployeesクラスにメソッドが追加される。

class Employees {
  private int baseSalary;
  public int calcSalary() {
    // 色々計算
  }
  // その他もろもろ
}

でも、自分で設計するときは、そうせずに↓みたいに別クラスにロジックを切り出すように作る。

class なんて名前になるだろうね {
  public int calcSalary(Employees emp) {
    // なにやら計算する
  }
}

ドメインモデル貧血症万歳!って感じです。
最近は、こっちのほうが現実の世界を現してるような気がしてきた。
現実では、従業員全員が自分の給与を計算したりはしてない。
給与計算は、別の誰かが従業員のデータを見てしてるはず。
そういった視点でみるとドメインモデル貧血症ちっくなつくりが自然に思えてきた今日この頃でした。

投稿日時 : 2007年9月19日 20:07

Feedback

# re: オブジェクト指向で開発? 2007/09/19 20:23 かつのり

自分もドメインモデルよりもトランザクションスクリプト派です。
データと業務が混在するのが気持ち悪いです・・・

# re: オブジェクト指向で開発? 2007/09/19 20:25 かずくん

データをValueObjectとして切り出せば、混在感も薄まる希ガス

# re: オブジェクト指向で開発? 2007/09/19 23:17 シャノン

給与計算メソッドは経理係が持つだろうが、給与プロパティは社員が持つだろうね。

# re: オブジェクト指向で開発? 2007/09/20 0:23 かずき

以前、「従業員クラスの持たせないと駄目だ!オブジェクト指向設計になってない」と声の大きなお客さんが言ってた事があって、考えるようになりました。

# re: オブジェクト指向で開発? 2007/09/20 10:02 επιστημη

んむ...
従業員に対して"あんたの給料いくら?"と尋ねるか、
経理課に対して"アイツの給料いくら?"と尋ねるか、ですな。

従業員が"給料いくら?"と尋ねられたとき、その実装内で

class 従業員 {
 public int 給料いくら?() {
  return 経理課.給料いくら?(this);
 }
}

すんでしょねー。
従業員が給与の算出に必要な情報をすべて持っているなら、
経理課に計算してもらわんでもえぇ。
経理課からは計算式だけをもらってくればえぇですね。

# re: オブジェクト指向で開発? 2007/09/20 12:38 かずき

なる~
聞かれたら丸投げってのもありですね。
実際には、○月の給料いくら?って聞かれたらWeb見に行っちゃいますけど(笑)

# ugg online 2012/10/19 16:02 http://www.superbootonline.com

What i do not understood is in fact how you are now not really a lot more well-preferred than you might be right now. You are so intelligent. You recognize thus considerably in relation to this topic, produced me personally imagine it from so many varied angles. Its like men and women aren't fascinated except it is one thing to accomplish with Woman gaga! Your personal stuffs outstanding. At all times take care of it up!

# longchamp pliage hobo 2012/12/15 15:43 http://www.sacslongchamp2012.info/sacs-le-pliage-l

I would love to take some sort of closer look at some of their memorabilia!

# echarpe burberry 2012/12/16 3:57 http://www.sacburberryecharpe.fr/category/sac-burb

Our pool need to be fed having those photopages for you to consider worth becoming area of the "Best Short review Collection".

# 安いトリーバーチ バッグ 2012/12/16 21:25 http://www.torybruchjp.info/category/トリーバーチ-店舗

Think it for a journal or perhaps magazine with general interest for everybody to read through. Funny, witty, controversial, entertaining, useful, acerbic, thoughtful, serious, curious, unexpected comebacks usually are welcome.

# burberry uk 2012/12/17 7:28 http://www.ukburberryoutlet.info/category/burberry

Our admins have a sharp eye and in some cases sharper senses - and additionally our Perfect Comments online community enjoys an amazing read. Come play around!

# burberry femme 2012/12/17 20:41 http://www.sacburberryecharpe.fr/category/burberry

I apply earbuds out and about because within their portability, even though I prefer over typically the ear.

# isabel marant 2012/12/18 5:35 http://sneakersisabelmrant-paris.webnode.fr

gripping revenues of remarks bursting from a photos.

# burberry en ligne 2012/12/18 21:53 http://sacburberrysoldesfr.webnode.fr/blog

Now i'm impressed by the quality of information in this particular website. There are loads of good resources here.

# burberry scarf 2012/12/19 13:36 http://burberryoutlet2013sale.webeden.co.uk/#/abou

Those are much more awesome. Looks similar to klipsch is absolutely made to do business with iProducts? I need android variants!

# longchamp uk sale 2012/12/21 3:51 http://bagslongchamp.webeden.co.uk

Great blog post, it's beneficial information.

# tt6262.com 2013/03/04 5:11 http://tt6262.com/

Because you can save your recipe in an enemy, explain to doing it to fail to someone. tt6262.com http://tt6262.com/

# Jordan Retro 12 5 6 2013/03/04 23:31 http://www.nikerow.com/

Really like is considered the existing difficulty of the way of life therefore the growth of whatever most of us affection. Jordan Retro 12 5 6 http://www.nikerow.com/

# reduction la redoute 2013/03/05 0:49 http://www.k77.fr/

Quite possibly Deity prefers mankind to meet up with quite a few erroneous customers until interacting with the right choice, with the intention that whenever we in the end satisfy the human being, we shall are able to sometimes be grateful. reduction la redoute http://www.k77.fr/

# code reduction la redoute 2013/03/06 21:24 http://www.k88.fr/

Don't look down upon, if you , yourself are upsetting, if you can't predict the person falling over gets interested any be happy. code reduction la redoute http://www.k88.fr/

# France Marque 2013/03/06 21:24 http://www.g33.fr/

True love is a lone rational and additionally acceptable solution involving human your life. France Marque http://www.g33.fr/

# robenuk 2013/03/06 21:32 http://www.c88.fr/

Romance, a friendly relationship, honour, be careful not to bring together people young and old over a commonplace hate to obtain a thing. robenuk http://www.c88.fr/

# Jordan 11 2013/03/06 21:42 http://www.nike44.com/

Exactly where you have nuptials whilst not absolutely love, you will get absolutely love whilst not nuptials. Jordan 11 http://www.nike44.com/

# casquette obey 2013/03/06 21:45 http://www.b66.fr/

An actual colleague can offer who overlooks your entire setbacks and consequently tolerates your entire successes. casquette obey http://www.b66.fr/

# destock jeans 2013/03/06 21:46 http://www.g77.fr/

Relationships remaining the minute each single colleague thinks as well as hook favourable position for several more. destock jeans http://www.g77.fr/

# casquette chicago bulls 2013/03/14 19:48 http://www.a77.fr/

Enjoy relates to the hectic problem towards the lifestyles as well growth of whatever all of us adoration. casquette chicago bulls http://www.a77.fr/

# casquette supreme 2013/03/16 7:27 http://www.b44.fr/

A genuine mate the so , who overlooks your favorite deficiencies together with tolerates your favorite success. casquette supreme http://www.b44.fr/

# usine23 2013/03/24 0:47 http://e55.fr/

Anyone that you just simply decide to purchase that has gives you is going to be bought from yourself. usine23 http://e55.fr/

# destockchine 2013/03/24 0:48 http://c99.fr/

Affection will be the established headache on the life-style and therefore the increase of what we absolutely love. destockchine http://c99.fr/

# casquette gavroche 2013/03/24 11:26 http://d99.fr/

You shouldn't discuss about it your enjoyment one fewer rosy rather than your body. casquette gavroche http://d99.fr/

# 3suisses 2013/04/07 1:33 http://ruenee.com/

Romance, friendship, honor, do not link up customers over a well-known hatred with respect to factor. 3suisses http://ruenee.com/

# Nike TN 2013 2013/04/07 6:22 http://www.9fr.fr/

Around the globe you'll probably be a person, though to a single woman you'll probably be the planet. Nike TN 2013 http://www.9fr.fr/

# 5fr.fr 2013/04/07 6:22 http://www.5fr.fr/

You shouldn't discuss about it your primary bliss to 1 a lesser amount of privileged rather than personally. 5fr.fr http://www.5fr.fr/

# gemo 2013/04/07 7:22 http://ruezee.com/

Felicity is really perfume it's not possible to dans le but de upon other types not including locating a small amount of sheds upon your self. gemo http://ruezee.com/

# bonprix 2013/04/08 7:36 http://ruemee.com/

You should not communicate an individual's contentment to just one less fortuitous instead of that you are. bonprix http://ruemee.com/

# coach outlet houston 2013/04/08 17:10 http://www.coachoutlet66.com/

Correct acquaintanceship foresees the requirements of additional other than proclaim it is really own personal. coach outlet houston http://www.coachoutlet66.com/

タイトル
名前
Url
コメント