473,379 Members | 1,174 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,379 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 3875
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">...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.