c# - Does it make sense to encapsulate fields in a public class in a Web Service? -
if have public class in wsdl specification user have fill send server, make sense encapsulate fields or it's better make public too?
it's never idea publicly expose class fields.
encapsulate fields , expose them via public properties. might using public field now, may want add additional logic have more control on how field read or written in future, lot easier properties , doesn't require changes consumer code.
you can use auto-implemented properties can defined cleanly in 1 line public field:
public string field1 { get; set;}
Comments
Post a Comment