Main differences between Property's and Variables in VB.net [duplicate] - vb.net

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Why use simple properties instead of fields in C#?
If I have a class, does it matter if I use a Variable instead of a Property? I mean, unless I need something to run during the get/set time period, does it really matter? It still gets the job done.

It doesn't necessarily "matter" which you do. The reason for using property get/set would be to validate values before they're assigned to the variable and ensure that it can't be directly accessed from outside the class.
If you only have a small application and your class won't be designed to be reusable, I don't see a problem with just using public variables.

Related

What is an Object and a Class in python? [duplicate]

This question already has answers here:
What is the difference between objects and classes in Python
(5 answers)
Closed 3 years ago.
I came across the following line:
Every list object that you create in Python is actually an instance of List class.
What does Class and Object actually mean?
Another similar post
I saw the above post but in that they explain the difference between object and class. But what exactly is a class if Object is an instance of class.
Edit:
What is an instance?
Think of classes as blueprints for objects. So for example, you will only have one car model blueprint, and that is your class. Every single model that is produced is an instance. Hope it helps.

Why methods' names are so long in Objective-C [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I've learned C/C++, Python, Matlab and many other language, but I was really surprised by the long method name in objective-c.
What's the advantage of using long name?
Why no other language use long name?
Thanks a lot.
It is something like code convention. Usually it is very useful.
But you can name your methods as you want. Also notice that it is not strongly required to name all parameters. For example you can create method
- (void)makeDateFromDay:(int)day month:(int)month year:(int)year
and call this way
[someObject makeDateFromDay:18 month:2 year:2014];
but you also can name it shorter
- (void)makeDateFrom:(int)day :(int)month :(int)year
and call like this
[someObject makeDateFrom:18:2:2014];
But it is not so readable, yes?
The plain answer is that the long method names are self-descriptive. (And since each argument is introduced through another method name part, the method name gets even longer.) The advantage is that the code reads really easily, and thanks to code completion there is no extra penalty for typing the whole thing by hand.
More methods are longer, more they speak themselves.
If you consider delegate method, in the method there is also the references
to class from the method being called because it can be very userfull to make some
kind of operation on class that conforms to protocol.
If you suppose to have an app where you have to do a lot of calc, like a shop application,
you can't declare all methods with the same name (for example sum) because when you have more than two methods with the same name you start to lose control on your code.
A lot of programmers using short syntax like name vars as:
a, b
But when you open code some months later you have to reconstruct the logic of program to know what a certain var does.
Give a long name to methods can be also usefull when you work in team to be more safe on method name replication.
Obj-C method names closely respect a convention with more rules than other languages. For example the last word of the method name is the name of the first argument.
- (id)valueForRow:(int)row Column:(int)column
In C++ this would probably be:
void getValue(int row, int column)

Does Go support templates or generics? [duplicate]

This question already has an answer here:
Generic Structs with Go
(1 answer)
Closed 8 months ago.
I know that Go doesn't have classes in the traditional OOP sense, but Go does provide a notion of interfaces that allows you do most of the OOP things you'd want to do.
BUT, does Go allow for something like creating a templated class? For instance, I'm reading through the source code for the container/list package. It defines a list and the list's associated methods. But in all methods, the values contained in the list are of type interface{} -- so, of any type. Is there any way to create a list that is constrained to only hold values of a particular type? int, string, Fruit... whatever.
Newer than gotgo, there's a code-generation-based package called "gen".
http://clipperhouse.github.io/gen/
gen is an attempt to bring some generics-like functionality to Go, with inspiration from C#’s Linq, JavaScript’s Array methods and the underscore library. Operations include filtering, grouping, sorting and more.
The pattern is to pass func’s as you would pass lambdas in Linq or functions in JavaScript.
Basically what #FUZxxl said.
Generics? Not at this time.
Templates? Not quite. There are third-party projects like gotgo which aim to add template
support by pre-processing files. However, gotgo is quite dead as far as I know.
Your best option is to use interfaces or reflection for the time being.
If you really want to use reflection, note that the reflect package offers a way to fill a typed function variable with generic (reflected) content. You can use this to use types the compiler
can check with your reflection based solutions.

Use cases to define a variable as `protected`? [duplicate]

This question already has answers here:
Should you ever use protected member variables?
(10 answers)
Closed 8 years ago.
I understand that one should use protected when one wants to make the variable visible in all classes that extend current class, but what does that mean exactly? What are the most common use cases?
I suppose another way to frame the question would be, what are the key cases when you would want a class variable to be visible from the class' children but not from external classes.
Most of the use cases of the 'protected' access modifier I've encountered, are instantiations of the 'Template Method' pattern.
In this pattern, a detail of an algorithm is delegated to the subclass.
In effect, protected access creates a hole in your class invariants: a subclass may abuse the member in such a way that your invariant doesn't hold anymore.
Most of the time, there are better design alternatives than protected access, dependency inversion being the first one coming to mind.
My advise? Don't publish your object's internals to anyone you don't trust. Use 'protected' with caution!
Protected variables help effectively access the variables of base class without going through the get / set constraints.
The usefulness of protected variables are significant in development of libs which are supposed to serve in other applications. It helps you freely use the variables in the environment of lib without making them public and when you finalize the inherited class, they are barred to outside environment.

Delegates in Objective-C [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How does a delegate work in objective-C?
Hello Community,
I have been trying to understand the concept of delegates in Objective-C. I tried following up the documentation, however I am looking for some really easy example to get familiarized as of how to send messages between delegates and if I want to create a custom delegate, how may I go further with that?
Hope someone could make me better understand this concept.
The basic concept of delegates is to delegate important decisions or information to some other object instance.
In most frameworks you use subclassing and override methods in order to hook into the application flow. It works but the drawbacks are many, for example:
You can not change the decision maker without a complete new subclass.
Without multiple inheritance you can only make decisions for one object (yourself).
There are four reasons why an object might want to call upon a delegate, and each of these four uses a keyword in the delegate method name to signal this. It's a naming convention only, but you should follow the pattern if you want to be a good citizen.
Ask if something should happen. For example: gestureRecognizer:shouldReceiveTouch:
Before something unavoidable is going to happen. For example: applicationWillTerminate:.
After something has occured. For example: accelerometer:didAccelerate:
And to retrieve data, this is more a data source than a delegate, but the line between the two are fuzzy. The name do not contain a defined name, but should contain the named piece of data that is requested. For example: tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:
As a general rule the first argument to any delegate method should be the named object instance requesting delegation.
Check here:How do I create delegates in Objective-C?
Or: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html#//apple_ref/doc/uid/TP40002974-CH7-SW18