Best Practices for OOP

  • Thread starter Thread starter Joe Kasta
  • Start date Start date
J

Joe Kasta

Hi,

I'm trying to determine what the proper way to create objects would be in C#
(or any language, practically).
There are two different ways of implementing objects that I can see, and I
hope someone can give their two cents as to which is more preferred.

Object 1: Have a Class with readonly properties and mutate all of the
private variables directly within the class. Any function within the class
may directly modify any private variable within the class.

Object 2: Have a Class with both sets of properties and only access the
Private Variables using those properties, Including directly within the
class (The Property itself, of course can mutate / access the variable, but
nothing else.)

I'm torn. I can see value in both.

In Object 1: It saves problems and you prevent any possible manipulation of
the properties from outside sources. (You can have a readonly Get property,
and any holding a reference the Object 1 can't manipulate the private
variable at all. This is good, right?!

In Object 2: You risk having outside objects manipulating the private
variables. BUT, in inherited classes, you can change practically anything
and not have to worry about changing a base class if you need functionality.


Any thoughts on this, people?

-J
 
Do what best suits you. Nuff said.

Just because design patterns have been written about, doesn't mean you have
to adhear to them.


--

Jack Mayhoff
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Jack Mayhoff said:
Do what best suits you. Nuff said.

Just because design patterns have been written about, doesn't mean you have
to adhear to them.

As much as I hate to...I have to agree on this. Do what makes sense in your
situation.
Don't be afraid to have to subclass or put a little extra work in to get the
project working.

However, this guy isn't actually from MS, so in general ignore him, ;).
 
Yeah,

I figured that one out pretty quickly Just goes to show you how professional
non-Microsoft people are..

Thanks for the assistance, though.

-J
 
Joe Kasta said:
Yeah,

I figured that one out pretty quickly Just goes to show you how professional
non-Microsoft people are..

Thanks for the assistance, though.

-J


Er... We haven't a clue what you're talking about. Presumably you are
referring to an earlier message here, but there are hundreds per day and we
don't know which one you have in mind.

Care to elucidate?
 
Michael A. Covington said:
Er... We haven't a clue what you're talking about. Presumably you are
referring to an earlier message here, but there are hundreds per day and we
don't know which one you have in mind.

He's referring to messages from "Jack Mayhoff [MSFT]" - including one
earlier in this very thread.
 
Back
Top