1)Is it a must to create both the property and methods in the
classes....if i does not uses property often....
can i just declare it inside the form and put all methods
separately to the classes...
Property is just a setter/getter function. You could and could not create your own property. Sample to this functions are the ones in Java. Something that looks like this
Code:
function getSomething() varialbe_type
return variable
end function
sub setSomething(something)
me.variable=something
end sub
2)Can i say that class is somehow act like the function procedure
as it can return the values except that it could be shared to all
forms if i put it in classes....
Class is not a function but a structure with a twist. A structure that has function and variables inside it. What's good about classes is the oop feature that can extend it's capability to another class. The one we know about inheritance.
3) Lastly, how to declare one or multiple classes that i need to
the various forms... I am not sure where the Inherits
should be place... is it
coding:
VB Code:
Public Class Sample
Inherits System.Windows.Forms.Form
Inherits Class1, Class2
Thanks
There is no multiple inheritance in .NET aside from C++. Dunno about any languages if they support multiple inheritance. You can do multiple inheritance by creating an interface and implements it on your class. Something like this
Code:
public class Sample
inherits Class1
implements Interface1
. . .
end class
public Class1
. . .
enc class
public interface Interface1
Sub DoThis()
Function DoThis2() as variable_type
enc interface
From there, your class Sample have the feature from Class1 and the functionality of your interface.
I heard from other forums that the current version of .NET does
not support polymorphism. So I can only have one inherits
statement at the class level.
However, other objects within the class can inherit other classes...
I heard from other forums that the current version of .NET does not support polymorphism. So I can only have one inherits
statement at the class level.
It does support morphing like the "Aliens" morphing like Mendhak. Seriously, it does support morphing
Code:
function f() as something
. . .
end function
function f(id as integer) as something
. . .
end function
That's morphing. Overloading and Overriding is a feature in morphing (The Mighty Morphing Power Ranger?, ). You mean multiple inheritance?
However, other objects within the class can inherit other classes......
You don't need to create a Sub New() if it's not need. I mean, if the need of your class is something like this dim something as new toytoysclass(somethingelse), you wouldn't bother to create a sub new() but a sub new(with_parameter). But I personally create all my classes with the sub new() (note: no argument).
BTW, it's the constructor, it gets fired if your class is instantiated. Everytime you create an instance of the class, the constructor gets called. Now with the morphing thing, you can also create another sub new with different signature as the default, that is sub new()
you means it is not so important....just create a blank sub New() inside every classes...
There are some usage of blank constructor. I don't know much so can't help producing much information. One usage I have with this blank constructor is, say for example, I have a GeneralCollection class that inherits the Payment class. Now, in my frmgeneralcollection (inherits from Form) there should be a reflection of the GeneralCollection class. Now I have to create an instance by default because I can add something to it. It's a scope of the frmgeneralcollection. In the events, I can add something, say... GeneralCollection.AddNatureOfCollections(...) that preserve the current instance of the GeneralCollection class. That is why in the scope of the frmgeneralcollection class I instantiated the GeneralCollection class without any arguments. Dim gncol As New GeneralCollection() (note: the blank argument), I can then recreate the class by gncol=New GeneralCollection() after the saving/updating/deleting it from the DataBase.
in what situation will you consider create a class best with
1) function procedure and property
2) sub procedure and property
3) Just property
4) All of the above together
My preference is the Function/Sub setting and getting member variables of the class. I found property a lot of work. Just my 0.02 but whatever floats your boat. Whatever you like.
Are you talking about this one? It's because those properties are Shared. A member of the class, not the object itself. Notice the Console.WriteLine()? WriteLine() is a shared member method of Console class. You need no intantiation. Instantiation is for object and we are dealing about the class member.
Hi
The class can be used by frmSummary without creating an instance of the class because the following properties are all declared Shared.
VB Code:
Shared ReadOnly Property NumberProcessed() As Decimal
Shared ReadOnly Property TotalPay() As Decimal
Shared ReadOnly Property OvertimeHours() As Decimal
Acording to MSDN The Shared keyword indicates that one or more declared programming elements are shared. Shared elements are not associated with a specific instance of a class or structure. You can access them by qualifying them either with the class or structure name, or with the variable name of a specific instance of the class or structure.
Regards
Jorge
"The dark side clouds everything. Impossible to see the future is."