function vs property? [duplicate] - asp.net-mvc-2

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What is Method, Property and Function ?
Can anyone tell me what is function and what is property?
Just a basic explanation.

Property denotes the object's state, Method denotes the object's behavior. Function is like method except for that it's not dependent upon an object (I'm guessing you don't really mean that).
For example, if you have a Car class, a property may be it's model, it's year, it's current speed etc., a method may be Stop, Drive etc.

see msdn: Properties, Methods

Additionally, pragmatically, properties will 'interact' with some tools. For instance, they will show up in the Properties window of VS.

Related

Matlab function command [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Assume that I have a subfunction seen in the below. What is the difference between these two
function a=b(x,y)
.
.
.
a=output
and
function b(x,y)
......
if I write it in second form how can I define it main function and how can I see its outputs.
Another question,
I found a code from here (http://www.mathworks.com/matlabcentral/fileexchange/21443-multiple-rapidly-exploring-random-tree--rrt-) including a function like:
%% SetObstacleFilename
function SetObstacleFilename(self,value)
if isa(value,'char')
self.obstacleFilename = value;
self.GenerateObstacles();
end
end
how can I use it in my main function? Moreover what is self.GenerateObstacles() command? There is no equality on it?
I think I see how both of your questions are related to the same thing. You really should've asked something along the lines of:
I always saw MATLAB functions written in the form function a=b(x,y), however recently I came across some code which included functions in the form function b(x,y) (e.g. function SetObstacleFilename(self,value)).... so what's up with that?
In order to understand the 2nd type of functions, you need to consider object-oriented programming (OOP).
The code example you found is taken from within a MATLAB class. Class-related functions are known in OOP as "methods", and this specific code in another programming language would take the shape of a void return type function\method.
Now consider the term object that refers to an instance of a class.
Traditionally, methods are limited to a single output. For this reason, some methods are designed to operate on objects (actually pointers, AKA "passing by reference") such that returning a value is not necessary at all, because the input objects are directly manipulated. Other cases when methods don't need to return anything may include functions that have some "utility" functionality (e.g. initialize something, plot something, output something to the console etc. - just like the self.GenerateObstacles() method you mentioned).
Regarding your other questions:
The self in SetObstacleFilename(self,value) looks like an instance of the considered class.
Usually to use class methods you need to instantiate an object using a constructor (which should be a function with the same name of the class), unless these methods are static.
To conclude - above are just the most fundamental basics of OOP. I won't attempt to teach you the whole OOP Torah while standing on one leg, so I am providing some additional materials below, should you be interested to further your understanding of the topic.
Hopefully, what's going on is a bit clearer now!
Here are some resources for you:
MATLAB's OOP Manual.
MATLAB's documentation on OOP.

Should I class contain another object or subclass another class? Has or Is? [duplicate]

This question already has answers here:
Prefer composition over inheritance?
(35 answers)
Closed 9 years ago.
I am making a program for studying chess openings, traps and maybe other related things. It has a class MoveSequence, which basically is an ordered list of objects from a class ChessPosition. I also have a class ChessOpening which has a sequence of moves and a name, an ECO-code (chess opening classification system) and probably some more stuff.
Should I implement ChessOpening as a subclass of MoveSequence, or should it just contain a MoveSequence object? The same question would apply for a class ChessTrap.
Don't think it matter so much what I choose in this simple problem. But I want to learn this stuff, so I was wondering if there is some principles, or rules of thumb, one should consider when making decision like this.
My 0.02$ worth:
If a possible subclass does not share basically all of the properties and methods of its superclass, I start to wonder.
Overriding methods to change behavior, or adding new properties and methods is normal. But when you hit that awkwardness when some of the superclass properties/methods are not applicable to the subclass, it gets creepy. (What do you do then, just ignore the invalid/inappropriate parts? Hope no one ever calls them? Stub them out and raise an error if they are used?)
If xxx is not really a yyy, maybe xxx and yyy are both zzz's. (Or if they just share common behaviors, maybe create a module to include, which is a standard Ruby/Rails practice.)
A real Computer Scientist may have a more concise and definitive answer...

Objective C - Difference Between VARType* vt and VARType *vt [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Placement of the asterisk in Objective-C
What is the differenct between the following:
(Assume we have a class calculator)
Calculator* calc;
Calculator *calc;
Also what is the need for pointers? Is it not possible to omit the star?
There is no difference between those two declarations, you could also do Calculator * calc if you're feeling adventurous.
As far as if you can omit the star, no, you cannot. It is a carry over from C and shows that calc is a pointer to a Calculator, and not a Calculator itself.
There is no difference between the 2 declaration is just an preference for typing.
Every thing on computers uses pointers. You need pointers java, c#, etc use pointers.
No is not posible to omit the star.

Objective c: All selectors of instance during runtime [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
List selectors for obj-c object
Does anybody know how to get all selectors that a instance respond to during runtime in objective C?
As answered here, #import < objc/runtime.h > and use class_copyMethodList().
In general, this is not possible. "The selectors an instance responds to" may be an infinite set. For example, it is possible to implement a class that is sent Roman numerals as messages and returns the corresponding integer value. If you want to know the precise set of instance methods implemented by a class at a given time (which is a different question), you can just use the Objective-C runtime functions to get a class's instance method list and walk up the class tree to find the ones it inherits from superclasses. Again, though, these are two totally different things. A class might have a method for a message that it chooses not to respond to and it might respond to messages for which it does not have a directly corresponding method.
dapptrace (Dtrace) is your friend.
on the man page (man dapptrace):
dapptrace prints details on user and
library function calls
dapptrace is written for the Dtrace scripting language (D). This means you can adjust dapptrace or pull ideas from it's script file to do many things. For instance:
wait for myFunctionWhichCreatesSpecialObject to be called. Store the object address that it returns (the special object). Print out any selectors invoked on that object.
You can also invoke dtrace directly to write simple single-line spells. I'll let you go search for those.
During runtime you would use
the class method "+ (BOOL)instancesRespondToSelector:(SEL)aSelector"
provided you know the selectors you want to check on.

Naming Conventions: What to name a boolean variable? [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 3 years ago.
Improve this question
I need a good variable name for a boolean value that returns false when an object is the last in a list.
The only decent name I can come up with is 'inFront', but I don't think that is descriptive enough.
Another choose would be 'isNotLast'. This is not good practice though (Code Complete, page 269, Use positive boolean variable names).
I am aware that I could change the variable definition. So true is returned when an object is the last and call the variable 'isLast', however, it would make this task easier if I had the first explanation.
isBeforeTheLastItem
isInFrontOfTheLastItem
isTowardsTheFrontOfTheList
Maybe too wordy but they may help give you ideas.
My vote would be to name it IsLast and change the functionality. If that isn't really an option, I'd leave the name as IsNotLast.
I agree with Code Complete (Use positive boolean variable names), I also believe that rules are made to be broken. The key is to break them only when you absoluately have to. In this case, none of the alternative names are as clear as the name that "breaks" the rule. So this is one of those times where breaking the rule can be okay.
hasFollowingItems? or hasFollowingXXXXs where XXXX is whatever the item in your list is?
Personally more than anything I would change the logic, or look at the business rules to see if they dictate any potential naming.
Since, the actual condition that toggles the boolean is actually the act of being "last". I would say that switching the logic, and naming it "IsLastItem" or similar would be a more preferred method.
isPenultimateOrPrior
isBeforeEnd
Haskell uses init to refer to all but the last element of a list (the inverse of tail, basically); would isInInit work, or is that too opaque?
How about:
hasSiblings
or isFollowedBySiblings (or isFolloedByItems, or isFollowedByOtherItems etc.)
or moreItems
Although I think that even though you shouldn't make a habit of braking 'the rules' sometimes the best way to accomplish something may be to make an exception of the rule (Code Complete guidelines), and in your case, name the variable isNotLast
A simple semantic name would be last. This would allow code always positive code like:
if (item.last)
...
do {
...
} until (item.last);
Two issues to think about
What is the scope of the variable (in other words: are you speaking about a local variable or a field?) ?
A local variable has a narrower scope compared to a field. In particular, if the variable is used inside a relatively short method I would not care so much about its name. When the scope is large naming is more important.
I think there's an inherent conflict in the way you treat this variable. On the one hand you say "false when an object is the last in a list", where on the other hand you also want to call it "inFront". An object that is (not) last in the list does not strike me as (not) inFront. This I would go with isLast.