473,503 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best Practices for OOP

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

Nov 15 '05 #1
5 2131
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.

"Joe Kasta" <J@microkroff.com> wrote in message
news:O4*************@TK2MSFTNGP10.phx.gbl...
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

Nov 15 '05 #2

"Jack Mayhoff [MSFT]" <v-******@online.microsoft.com> wrote in message
news:ew**************@tk2msftngp13.phx.gbl...
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, ;).

--

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.

"Joe Kasta" <J@microkroff.com> wrote in message
news:O4*************@TK2MSFTNGP10.phx.gbl...
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


Nov 15 '05 #3
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
Nov 15 '05 #4

"Joe Kasta" <J@microkroff.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
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?
Nov 15 '05 #5
Michael A. Covington <lo**@www.covingtoninnovations.com.for.address>
wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1954
by: byrocat | last post by:
I'm chasing after a documetn that was available on one of the Microsoft websites that was titled somethign like "MS SQL Server Best Practices" and detailed a nyumber of best practices about...
136
9200
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
13
2251
by: john doe | last post by:
A quick question, about so-called 'best practices', I'm interested in which of A/B of the two examples people would choose, and why. public enum MyEnum { Option1 = 0, Option2 = 1, Option3 =...
1
1396
by: | last post by:
Hi can someone send or point me to Any nice Material on .NET Best Practices -regards
2
1799
by: Amelyan | last post by:
Could anyone recommend a book (or a web site) that defines best practices in ASP.NET application development? E.g. 1) Precede your control id's with type of control btnSubmit, txtName, etc. 2)...
4
1814
by: Luis Esteban Valencia | last post by:
Hello. Can somebody recomend me books of design patterns in c# and best practices too.
10
3416
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
0
1674
by: Louis Aslett | last post by:
I hope this is the correct newsgroup for this query (if not please give me a pointer to where is best): I understand the theory of normalisation etc and am trying to follow best practices in the...
10
2961
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? ...
3
2230
by: John Dalberg | last post by:
I am looking for an ASP.NET application on CodePlex which exemplifies best practices for the following: - Use of interfaces - Seperation of the UI, business and data tiers - Data Tier that uses...
0
7192
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7315
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.