473,762 Members | 7,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3894
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

"Ravichandr an 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
2912
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") Response.Write rs("FirstName") Response.Write rs("MiddleInitial") All fields are populated and are single terms. I would expect "LastNameSuffixFirstNameMiddleInitial" ("UserIIITestA" in my test record) to
1
2873
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();'>"); document.write("<OPTION VALUE='0.345066110642241'>Argentina Peso </OPTION>"); document.write("<OPTION VALUE='0.790200069503053'>Australia Dollar
1
2005
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 the file name. I'd like to display this error string, regardless of it's contents. Right now, depending on the error string, I get an error message about missing a semicolon or some such. I've tried using Encode and Server.HTMLEncode with no...
8
17920
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. How do I do it? I think one way is to write the entire table out in document.write("<table>...) but I'd like to know if it is possible to access a particular cell in a table.
2
5779
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
11163
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 character to the port using this: write (filedescriptor,"a",1);
0
5893
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. Basically what im trying to do is the following: - a client connect to a server using sslsocket. - server receive the connection and reply with the first part of the data and keep the connection open. - then client receive the reply and request for...
8
7107
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 overwrites the current page. Is there any way I could load a new tab or window, and put the new content into it? Here is the script I am using right now:
1
3818
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"> <!-- var strBGCol = "#ADCED7"; document.write("<table border='0' width='100%' cellpadding='0' cellspacing='0'>"); document.write("<tr>");
0
9554
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9377
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9811
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5266
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3913
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
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.