473,390 Members | 1,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

Write-Only Properties

Hi,

MS Class Library Guidelines clearly discourages use of Write-Only properties
yet they're continuously availed in .NET after VB 6. Personally, I really
don't use them anywhere. Tend to find it as giving the 'highest' possible
access to data as compared to a plain read.

However, out of more than a passing interest, does anyone know of a clear
cut reason why developers are clearly discouraged from using Write-Only
properties?
Jul 21 '05 #1
5 3876
Write-only properties usually indicate a flawed design. If you are referring
to this FxCop design rule then, yes, it is not recommended to use write-only
properties because they do not server much purpose. What is the point in
asking the user to supply a value but not allow him to read it ? If a class
requires some value it is supplied through read-write properties,
constructors, method parameters and not through write-only properties because
it is not conventional. Hence, it is a flawed design.

with regards,

J.V.
"Disiac" wrote:
Hi,

MS Class Library Guidelines clearly discourages use of Write-Only properties
yet they're continuously availed in .NET after VB 6. Personally, I really
don't use them anywhere. Tend to find it as giving the 'highest' possible
access to data as compared to a plain read.

However, out of more than a passing interest, does anyone know of a clear
cut reason why developers are clearly discouraged from using Write-Only
properties?

Jul 21 '05 #2
Write-only properties usually indicate a flawed design. If you are referring
to this FxCop design rule then, yes, it is not recommended to use write-only
properties because they do not server much purpose. What is the point in
asking the user to supply a value but not allow him to read it ? If a class
requires some value it is supplied through read-write properties,
constructors, method parameters and not through write-only properties because
it is not conventional. Hence, it is a flawed design.

with regards,

J.V.

"Disiac" wrote:
Hi,

MS Class Library Guidelines clearly discourages use of Write-Only properties
yet they're continuously availed in .NET after VB 6. Personally, I really
don't use them anywhere. Tend to find it as giving the 'highest' possible
access to data as compared to a plain read.

However, out of more than a passing interest, does anyone know of a clear
cut reason why developers are clearly discouraged from using Write-Only
properties?

Jul 21 '05 #3
I agree, properties (in general) imply a 2-way or binary communication
between 2 objects and a write-only property on an object implies a 1-way or
unary communication between 2 objects.

Its considered bad form to use a write-only property because it breaks the
OO rule for properties where properties are used for 2-way communication. A
write-only property should really be made into a method call instead because
it's more appropriate since method calls imply a 1-way communication between
objects.

Besides someone might be tempted to make your write-only property into a
read-write property which would go against your initial design.

HTH,
Jorge

"Ravichandran J.V." wrote:
Write-only properties usually indicate a flawed design. If you are referring
to this FxCop design rule then, yes, it is not recommended to use write-only
properties because they do not server much purpose. What is the point in
asking the user to supply a value but not allow him to read it ? If a class
requires some value it is supplied through read-write properties,
constructors, method parameters and not through write-only properties because
it is not conventional. Hence, it is a flawed design.

with regards,

J.V.

"Disiac" wrote:
Hi,

MS Class Library Guidelines clearly discourages use of Write-Only properties
yet they're continuously availed in .NET after VB 6. Personally, I really
don't use them anywhere. Tend to find it as giving the 'highest' possible
access to data as compared to a plain read.

However, out of more than a passing interest, does anyone know of a clear
cut reason why developers are clearly discouraged from using Write-Only
properties?

Jul 21 '05 #4
The property syntax is just a nice way to make using getter and setter
accessor methods to wrap an internal field more intuitive, easy to read,
etc.
If you only want to set a value, you do not need (or want) the intuitive
feel of property syntax because it will more likely confuse developers
rather than help them. When a developer sees a property, it is natural
to expect to be able to read it after writing it.
For cases when you just need to set an internal value, it makes more
sense to create a method that takes the value as a parameter. Then
there is no inherent expectation that the consumer of your class should
be able to read the value back.

Disiac wrote:
Hi,

MS Class Library Guidelines clearly discourages use of Write-Only properties
yet they're continuously availed in .NET after VB 6. Personally, I really
don't use them anywhere. Tend to find it as giving the 'highest' possible
access to data as compared to a plain read.

However, out of more than a passing interest, does anyone know of a clear
cut reason why developers are clearly discouraged from using Write-Only
properties?

Jul 21 '05 #5
Hi,Thanks. I agree with the sentiments so far. The advocacy for Write-Only
properties on the web seems close to hinge around the following example:

"..a password property on a security object. There's no reason to read the
password back, but we would, sometimes, want to set it.

Seems the solution to the example is flawed in my mind. Whats your take?

"Joshua Flanagan" wrote:
The property syntax is just a nice way to make using getter and setter
accessor methods to wrap an internal field more intuitive, easy to read,
etc.
If you only want to set a value, you do not need (or want) the intuitive
feel of property syntax because it will more likely confuse developers
rather than help them. When a developer sees a property, it is natural
to expect to be able to read it after writing it.
For cases when you just need to set an internal value, it makes more
sense to create a method that takes the value as a parameter. Then
there is no inherent expectation that the consumer of your class should
be able to read the value back.

Disiac wrote:
Hi,

MS Class Library Guidelines clearly discourages use of Write-Only properties
yet they're continuously availed in .NET after VB 6. Personally, I really
don't use them anywhere. Tend to find it as giving the 'highest' possible
access to data as compared to a plain read.

However, out of more than a passing interest, does anyone know of a clear
cut reason why developers are clearly discouraged from using Write-Only
properties?

Jul 21 '05 #6

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

Similar topics

10
by: Greg Hurlman | last post by:
I've got what I'm sure is a very simple problem. In an ASP page, I am trying to write out 4 fields from a recordset in succession: Response.Write rs("LastName") Response.Write rs("Suffix")...
1
by: techy techno | last post by:
Hii Just wanted to know how can I decorate my texboxes and Listmenu which is called from a JS file using the following code below: document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>");...
1
by: Bob Murdoch | last post by:
I have a situation where I call a COM object from ASP that is supposed to create a file. On occasion, especially during development, the output of the COM function is an error string rather than...
8
by: Ben | last post by:
Hi all, Just wondering how to write (using document.write) to a table cell. I have table with 3 rows and 3 colums. I want to write from within the Javascript to say third column of a first row....
2
by: bissatch | last post by:
Hi, I am trying to use JavaScript to write a table column on a web page. The code is as follows: <html> <head> <script> function displaycount() {
4
by: Tom Van Ginneken | last post by:
Hi, I need to write binary data to a serial port. I am using this function: #include <unistd.h> ssize_t write(int fd, const void *buf, size_t count); I am able to write a alpha-numeric...
0
by: kuguy | last post by:
Hi all, I'm new to the forums, so I hope this isn't in the wrong place... I have that "Software caused connection abort: socket write error" exception error that i've never meet before. ...
8
by: Mateusz Viste | last post by:
Hi, I am trying make some multimedia files playable from my website. So far, I am able to generate dynamically a new page containing the right <embed> section. However, when I load my script, it...
1
by: celeroSolutions | last post by:
This code works in my site in IE, but not in FireFox, and I'm stuck as to why! Any ideas? (The image paths are correct, I've tested these.) <script language="javascript" type="text/javascript">...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.