Information Technology Reference
In-Depth Information
their storage. You can't access that backing field, because the field name is
an invalid C# token (it is a valid CLR symbol). That makes binary seriali-
zation very brittle for types that use automatic properties. You cannot write
your own serialization constructor, or GetObjectData methods to access
those backing fields. Serialization will work for the simplest types, but any
derived classes, or future additional fields will break code. And, by the time
you discover the problem, you'll have persisted the original version in the
field, and you won't be able to fix the issue. Anytime you add the Serializable
attribute to a class, you must concretely implement the properties with
your own backing store.
The .NET Framework provides a simple, standard algorithm for serializ-
ing your objects. If your type should be persisted, you should follow the
standard implementation. If you don't support serialization in your types,
other classes that use your type can't support serialization, either. Make it
as easy as possible for clients of your class. Use the default methods when
you can, and implement the ISerializable interface when the default attrib-
utes don't suffice.
Item 28: Create Large-Grain Internet Service APIs
The cost and inconvenience of a communication protocol dictates how
you should use the medium. You communicate differently using the
phone, fax, letters, and email. Think back on the last time you ordered
from a catalog. When you order by phone, you engage in a question-and-
answer session with the sales staff:
“Can I have your first item?”
“Item number 123-456.”
“How many would you like?”
“Three.”
This conversation continues until the sales staff has your entire order, your
billing address, your credit card information, your shipping address, and
any other information necessary to complete the transaction. It's com-
forting on the phone to have this back-and-forth discussion. You never
give long soliloquies with no feedback. You never endure long periods of
silence wondering if the salesperson is still there.
Contrast that with ordering by fax. You fill out the entire document and fax
the completed document to the company. One document, one transac-
 
 
Search WWH ::




Custom Search