Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# object Oriented
The question in general is:
Is it a right design to add functionality to primitive objects, so that the object can "take care of himself"
 
Recent example:
I have a singleton logMngr. The logMngr saves records of different types to different Azure Tables. records are received, queued as BaseRecord, and then saved to Db with different thread using threading.Timer. We have 2 ideas:
 
1.The BaseRecord has an abstract method"saveToDb", and each record knows how to save himself to Db(the table name, the keys...) save to Db needs to use DAL singleton to do that. Maybe it is not a good idea for primitive type to have such a complex functionality, But the code is very "object oriented"
 
2. use:
 
if (record is xRecord){logMngr.SavexRecordToDb}
 
, and then it is not an open - close code. We do not expect to have more record kinds.
 
Any insights? Maybe a better idea than both?
 
Thank you, Tal
Posted 5-May-13 20:53pm
Edited 5-May-13 21:13pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It is always good to add methods to an object so that the object is cohesive and knows what to do with data provided to it.
For e.g. a save to database class could have add / delete and update methods implemented within the class.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,800
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 6 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100