Jason Mauss' Blog Cabin

Because someone's got to do the dirty work

Blog-Flair

Blogroll

Links

How to determine object responsibility?

Right now I'm working on a project that requires its own custom registration/authentication system and it got me thinking about object responsiblity and OO design.

I'll pose this question and see what kind of opinions everyone has.

I have a "User" class with the usual properties - first name, last name, email, etc.etc.

Should my User class have a method named "Register" where the User object is responsible for knowing how to register itself - OR - should I have a 'Register' method in say, some kind of security class that accepts a User object and uses the property values to register the User? I've abstracted all the direct DB interaction code into a data access library but where the Register method belongs - in terms of good standard OO design - still has me thinking. I might have to dig up my copy of "Object Thinking". It's been a while since I read it but I remember it having good stuff on topics like this.

What do you think the right design is?

Comments

Xerxes said:

i've seen a lot of different architectures over the years, and i've found that there's no one "right design - most good design techniques seem to work well...Having said that, there are a lot of bad ways of doing it too ;)

Under a pure BusinessObject model, you'd implement it using the former style - all logic related to operating on the User is contained within the user. Downside with that approach is that your User object becomes quite heavy. In some cases you'll find that you cant instantiate an object without also instantiating other dependencies. On the positive side however, you've achieved 100% OO encapsulation. As a side note, if you subclass User and create a SpecialUser, you can override the save behaviour unique to this new class.

If you implement it using the latter, you're still achieving similar results, and you're still ensuring separation of concerns, but you're allowing for other objects which may inherit from User to also use that core functionality without being able to change it, as in the example above. eg: The SpecialUser could also be saved under this approach. If the intention was that the SpecialUser cannot be saved, then you'll now have to implement that logic in your Security class, rather than being able to override the implementation of SpecialUser. If you do go down this approach, I'd recommend passing interfaces rather than classes as method arguments. Using interfaces will make it easier to mock test your code.

just my $0.02

# July 17, 2008 6:52 PM

Ian Qvist said:

It depends on the demands of the application. Should you focus on extensibility? (Service pattern, modules, third party authentication systems) Consistency? (Factory pattern) or something else?

I would personally base my design on extensibility. Later you might switch to something like OpenID for authentication and that would be easier if you had a clear interface between your application and the authentication mechanism.

Abstract away the authentication part. Make sure to use interfaces (as minimal as possible. By that I mean lightweight) to define a low coupled architecture between application and authentication.

As for the registration part, do as you see fit. I would do the same thing as with the authentication part.

BTW: Why not use a DAL (Data Access Layer) generation tool such as Subsonic, NHibernate or LINQ?

# July 17, 2008 8:20 PM

Andrew said:

According to Bertrand Meyer’s “Object-Oriented Software Construction”, the essence of object-oriented is that instead of a bunch of functions, and a bunch of data, pieces of data are grouped together with the functions that operate on them into things called “objects”.

So if your register method doesn’t actually operate on data in the user object -- it uses the user data as input but does it’s actual work on a central database -- then the register() method doesn’t belong in the user class.

# July 24, 2008 5:24 PM

Samuel said:

and after I read the previous ,

# October 19, 2008 3:57 PM

Websites tagged "oodesign" on Postsaver said:

Pingback from  Websites tagged "oodesign" on Postsaver

# January 10, 2009 6:02 AM

Buy oem software online said:

5PhFHf Yeah, it is clear now !... Just can not figure out how often do you update your blog?!....

# November 6, 2011 1:12 PM

weight loss aids said:

Yeah, it is clear now !... Just can not figure out how often do you update your blog?!...

# October 16, 2012 2:05 PM

online business ideas said:

I think this is a real great post. Much obliged.

# October 18, 2012 1:01 PM

payment processing services said:

Honestly, not bad news!...

# October 19, 2012 6:01 PM

euroffice said:

A round of applause for your article.Thanks Again. Keep writing.

# October 20, 2012 12:40 PM

euroffice said:

Very informative blog article.Much thanks again. Really Great.

# October 20, 2012 3:01 PM

hire a graffiti artist said:

Im thankful for the article post. Much obliged.

# October 21, 2012 3:09 AM

green coffee extract said:

Sorry for the off-topic, could you tell where I can get such a nice pattern for my blog ?!...

# October 21, 2012 1:20 PM

wedding linens tampa said:

Well, actually, a lot of what you write is not quite true !... well, okay, it does not matter:D

# October 21, 2012 2:17 PM

narrowboat layouts said:

Im grateful for the blog post.Thanks Again. Really Great.

# October 23, 2012 10:23 PM

ways to make money online said:

Honestly, not bad news!...

# October 25, 2012 4:51 AM

how to last long in bed said:

Im grateful for the blog.Thanks Again.

# October 25, 2012 8:18 AM

cb-1 weight gainer review said:

Good post! Found a lot of new and interesting! Will share the link with others:D

# October 26, 2012 10:11 AM

slim fast us said:

Yeah, it is clear now !... Just can not figure out how often do you update your blog?!...

# October 27, 2012 1:02 PM

onsite flu vaccination said:

I do`t regret that spent a few of minutes for reading. Write more often,  surely'll come to read something new!...

# October 28, 2012 5:24 AM

punto banco said:

I am getting married on the 15th of November. Congratulate me! Then will be here rarely!...

# October 28, 2012 6:28 AM

printed paper bags said:

I subscribed to RSS, but for some reason, the messages are written in the form of some hieroglyph (How  can it be corrected?!...

# October 29, 2012 3:03 PM

Signs said:

Interesting. We are waiting for new messages on the same topic!!...

# October 29, 2012 4:10 PM

remington coupon discount code said:

Totally agree with you, about a week ago wrote about the same in my blog..!

# October 29, 2012 5:20 PM

SEO Companies said:

Thanks for the news! Just was thinking about it! By the way Happy New Year to all of you:D

# October 29, 2012 6:27 PM

Joules said:

Yeah, it is clear now !... From the very beginning I did not understand where was the connection with the title !!...

# November 1, 2012 2:47 PM

Microsoft Office 2010 Keygen said:

I am glad that your blog is constantly evolving. Such posts only gain in popularity!...

# November 1, 2012 3:53 PM

Moncler Jacken said:

Honestly, not bad news!...

# November 4, 2012 2:14 PM

Moncler Jakke said:

Sometimes I also see something like this, but earlier I didn`t pay much attention to this!...

# November 4, 2012 3:21 PM

ADT Authorized Dealer Waco said:

The topic is pretty complicated for a beginner!...

# November 4, 2012 5:36 PM

Moncler Outlet said:

Yeah, in my opinion, it is written on every fence!!...

# November 5, 2012 5:09 AM

Casin� Online Italiani Autorizzati AAMS said:

Thanks for the article! I hope the author does not mind if I use it for my course work!...

# November 6, 2012 10:19 AM

Anuncios Putas said:

Many thanks for your good publish. I'll take the notes you've written.

# November 20, 2012 4:16 PM

pills for lose weight said:

NrLDH4 I really like and appreciate your article post. Cool.

# January 31, 2013 12:38 PM

Weis said:

It's truly very difficult in this active life to listen news on Television, therefore I simply use web for that reason, and obtain the most up-to-date information.

# April 15, 2013 6:51 PM

Arroyo said:

Hello, its fastidious article regarding media print, we all know

media is a impressive source of information.

# May 8, 2013 4:24 PM