473,568 Members | 2,795 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 2138
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.c om> wrote in message
news:O4******** *****@TK2MSFTNG P10.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.m icrosoft.com> wrote in message
news:ew******** ******@tk2msftn gp13.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.c om> wrote in message
news:O4******** *****@TK2MSFTNG P10.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.c om> wrote in message
news:%2******** *******@TK2MSFT NGP09.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.covin gtoninnovations .com.for.addres s>
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.co m>
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
1957
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 securing the server. Included in this was revoking public access to the system table objects. Can someone post the URL where I can pick this up, or...
136
9250
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 code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to...
13
2262
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 = 2, Option4 = 3
1
1399
by: | last post by:
Hi can someone send or point me to Any nice Material on .NET Best Practices -regards
2
1806
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) Group relevant .aspx files into subfolders within your project etc.
4
1816
by: Luis Esteban Valencia | last post by:
Hello. Can somebody recomend me books of design patterns in c# and best practices too.
10
3426
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 somewhere that each folder under the "web site" is compiled in separate assembly. I however, did not find that the "web site" creation in vs.net...
0
1681
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 design of the database for a new project, but I am unsure as to the best practice when one wants to store data relating to combinations of...
10
2971
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? public class MyClass private _variableName as integer public property VariableName as integer
3
2233
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 Enterprise Libraries data layer (if possible) - Use of providers (if possible) - use of factories (if possible) - use of caching - Session...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5217
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2101
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 we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.