|
Thanks for the links.
Still, it confuses me a bit, in the way that I have to give two different names in order to describe one object variable. like in the example above. The word 'Category' has a meaning for my class, but I am obliged to use a different word for the field, therefore I chose cat, but I find it poor in a semantic way.
Also, I am wondering if that is a Microsoft's "invention" or a general OOP thinking. Does it exist in Java too? I never met it in C++, MFC or other frameworks, nor in UML.
|
|
|
|
|
nstk wrote: The word 'Category' has a meaning for my class, but I am obliged to use a different word for the field, therefore I chose cat, but I find it poor in a semantic way.
Typically you will use Category for the property name and category or _category for the local variable name.
The same OO concept existed in C++ - it was simply a public method though. Properties are not necessary, it's just a new way of saying "public method that returns a value and keeps the value private." In C++ you'd simply write a public function, and some people even used the word "Get".
public int GetCategory()
{
return category;
}
public void SetCategory(int i)
{
category = i;
}
Same thing. However C# property offers you a convenient way of not even declaring the local variable! For example this works without even declaring your local variable called "cat".
public int Category
{
get;
set;
}
Again, this is for future use, where you have the option of changing how Category gets implemented (you can add a variable later, or write the get or set methods with some different code, but the caller would never need to know.) In the mean time, the compiler generates a local variable under the covers for you.
|
|
|
|
|
Let me give you the strong need of property in C#.
Suppose there's one field <code> CustomerID and you have assigned CustomerIDProperty to get and set values for CustomerID .
Now After a years requirements being changed and They say they need some validation on CustomerID now you can not change or not advisable to put a check of CustomerID everywhere in the code, At that time you can simply put check at set method of CustomerIDProperty to be rescued.
Property is introduced because of the changing requirement in software field.
"Walking on water and devloping a software both are the easy things,Provided both FROZEN".
|
|
|
|
|
Hiren Solanki wrote: Let me give you the strong need of property in C#.
...
Property is introduced because of the changing requirement in software field.
Property was introduced just as a convenience, not because of any need. The change requirement could easily be implemented with normal methods as in C++. It's a quicker way to code for the developer, it's a quicker way to call for the consumer (no parentheses required), offers an auto-generation option, and signifies intent of the developer with fewer comments (a property is used when there is little calculation and no side effects). None of these are necessary though.
|
|
|
|
|
Also that Interfaces can specify properties, but not fields.
|
|
|
|
|
It also gives hints at what to look for when reflecting through an object. IE Some asp.net data grids will auto bind columns to all properties of an object.
|
|
|
|
|
kevinnicol wrote: Some asp.net data grids will auto bind columns to all properties of an object.
That's true and good point, but that's a .NET issue that wasn't applicable to C++.
modified on Friday, December 17, 2010 2:40 PM
|
|
|
|
|
oops, thought I was in the C# forums, must have stumbled into the C++ forums by accident.
|
|
|
|
|
kevinnicol wrote: oops, thought I was in the C# forums, must have stumbled into the C++ forums by accident
The point is to answer in context of the OP's questions, and if you had taken the time you spent on your clever sarcasm and spent it on reading all the OP's posts instead, you'd know he was coming from an OO background from C++. So I think you need to decide if you want to help someone with a question in context, or if you want to show off your mad skilz
The OP said "I am wondering if that is a Microsoft's "invention" or a general OOP thinking. I never met it in C++." By way of my response to you, I was telling him that data grid data binding with properties is a Microsoft-specific invention for C#/.NET, and not general OOP thinking. I replied to your post to help him and the lurkers, not educate you.
But as a token of goodwill, I'm still willing to educate you. You misused "IE" in your previous post. You might want to look that one up.
|
|
|
|
|
There was no sarcasm intended, I just saw your reply in my email and truly thought I had made a reply in the wrong forum. There was no intent of sarcasm or showing of my "mad skilz". I will choose to take your token of goodwill as that and not passive aggression; in the future will use eg. instead of ie. in those cases. Thanks.
|
|
|
|
|
kevinnicol wrote: There was no sarcasm intended
Oh sorry, my bad! Since you already know about e.g., you're ahead of 90% of the people out there....
|
|
|
|
|
Everybody knows about exempli gratia and id est.
They are learned in elementary school.
|
|
|
|
|
ha ha yeah, right! If I only had a nickel for every time i.e. got misused.....
|
|
|
|
|
Because you can then provide validation code. But if you don't want to, then try an automatically-implemented property instead.
|
|
|
|
|
nstk wrote: As I know from OOP theory, the purpose of private Properties is to have the variables of an object protected from other classes, that could accidentaly change their value, thus provoking complications in a software. Am I correct till here?
Only partially. The other reason is to hide the implementation, so that it can change in the future. The calling code only needs to know the property name (or private function name). However you can change how you calculate the value.
So it's for future change, as well as current privacy. That's where the complication of properties comes in handy. Next month, you might rewrite your Category property to look like this
public int Category
{
get {
if (cat < 0) return 0;
else return cat;
}
set { cat = value; }
}
|
|
|
|
|
Hi,I'm a beginner,I'm learning develop windows forms applications,during these days I have developed several off-line programming.And I think that they are impracticability,so, I want to learn how to develop C/S programs like MSN or others,what should I do ? If you can recommend some books is the best.Thank you!
I'm a Chinese boy,my English is not good,this is my first time posting question on this forum.
If you can understand Chinese, Follow is in Chinese:
我是一名初学者,正在学习windows窗体程序开发,我也写了一些程序,但是都是单机程序,我想学习开发C/S架构的程序,需要学习哪些?就像MSN或者其他的软件,如果能推荐一些书籍的话更好,谢谢!
modified on Friday, December 17, 2010 1:40 AM
|
|
|
|
|
It looks like you are asking how to develop web based applications. If that is true then you should study ASP.NET[^], and I am sure there will be some books published in Chinese on the subject. You could also try asking your question in the Chinese Forum[^].
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Not ASP.NET,I want to learn "Client-Server Based" programming,for example:Issue Vision.
Should I learn TCP/IP、COM+、Web Services、remoting??? It's right?
|
|
|
|
|
I would suggest buying a book or search the internet for references on Client Server; this will give you more information and you can select the ones that fit your needs.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
For .NET you should consider WCF. I would do some internet searching for .NET client/server primers, or subscribe to an online book service like Safari Bookshelf so you can read any tech book you want as your questions and needs change.
|
|
|
|
|
Thank you.I just find <<professional c#="" 2008="">>,published by WROX.
|
|
|
|
|
It's a decent C# book, but I don't see a whole lot of C/S in there. Also, it will be 2011 in a few days so you probably want to be working with VS 2010?
|
|
|
|
|
I usually work with VS2005 or 2008.
|
|
|
|
|
Hide I'm going to develop a program like digital signage. I want to save some audio, video and image files in a databse and display it in ascheduled interval. Can anybody help me, How can I do this? Which technology I can use? Please help me.
Thanks in advance.
|
|
|
|
|
More information is required to even point you in the correct direction!
How are you going to deliver this, internal app or over the web?
What are your existing skills?
What do you mean by digital signage in reference to media files?
What database do you intend to use?
Never underestimate the power of human stupidity
RAH
|
|
|
|