3

オブジェクト指向設計では、次のうちどれが優れていますか?

次のようなメソッドでパラメーターを送信します。

obj.InsertRecord("raed","1987")

または次のようなプロパティを使用します。

obj.name= "raed"
obj.year= "1987"
obj.InsertRecord() 
4

2 に答える 2

8

If you send parameters, you'll have to alter the InsertRecord() signature every time the obj's class signature changes (for example if you add a description property), given you will want to save those new properties.

Also the object itself should not be bothered with saving itself. That is not the object's responsibility. So, something like this is the most future-proof:

ObjectStorage.InsertRecord(obj);
于 2013-02-03T13:10:11.040 に答える
2

Object oriented programming, this is preferred: obj.InsertRecord("raed", "1987");

Component Oriented programming, the latter is preferred: like this:

obj.name = "raed";
obj.year = "1987";
obj.InsertRecord();

Btw, this belongs to programmers.stackexchange

于 2013-02-03T13:09:38.370 に答える