Q...Characteristics of OOPS??
Following are the characteristics of the OOPS
Encapsulation: The wrapping of data in to a single unit is known as encapsulation....Data encapsulation si the most powerful feature of a class...The data is not accessible to the outside world and only those function which are wrapped in the class can access it...These function provide the interface between the object data and program...
Inheritance:Inheritance is the property in which, a derived class acquires the attributes of its base class. In simple terms, you can create or 'inherit' your own class (derived class), using an existing class (base class). You can use the Inherits keyword for this. .....Inheritance will allow you to define a very general class(Existing), and then later define more specialized classes (New class) by simply adding some new details to the older . This saves work, because the more specialized class inherits all the properties of the general class and the programmer need only program the new features.
Data abstraction: Data abstraction refers to, providing only essential information to the outside word and hiding their background details ie. to represent the needed information in program without presenting the details...Data abstraction is a programming (and design) technique that relies on the separation of interface and implementation..
Polymorphism: Polymorphism is an another OOPS concept..Polymorphism means ability to take more than one form...Poly means many and morph means form. Thus, polymorphism refers to being able to use many forms of a type without regard to the details...It has the ability to process objects differently depending on their data types...Polymorphism is the ability to redefine methods for derived classes...
Encapsulation: The wrapping of data in to a single unit is known as encapsulation....Data encapsulation si the most powerful feature of a class...The data is not accessible to the outside world and only those function which are wrapped in the class can access it...These function provide the interface between the object data and program...
Inheritance:Inheritance is the property in which, a derived class acquires the attributes of its base class. In simple terms, you can create or 'inherit' your own class (derived class), using an existing class (base class). You can use the Inherits keyword for this. .....Inheritance will allow you to define a very general class(Existing), and then later define more specialized classes (New class) by simply adding some new details to the older . This saves work, because the more specialized class inherits all the properties of the general class and the programmer need only program the new features.
Data abstraction: Data abstraction refers to, providing only essential information to the outside word and hiding their background details ie. to represent the needed information in program without presenting the details...Data abstraction is a programming (and design) technique that relies on the separation of interface and implementation..
Polymorphism: Polymorphism is an another OOPS concept..Polymorphism means ability to take more than one form...Poly means many and morph means form. Thus, polymorphism refers to being able to use many forms of a type without regard to the details...It has the ability to process objects differently depending on their data types...Polymorphism is the ability to redefine methods for derived classes...
Q.....OOPS , OBJECT , CLASSES
Object oriented technologies provide many benefits to software development and their procedure,....Using the object oriented programming your overall program is made up of lots of different self contained components, each of which has a specific role in the program and all of which can talk to each other in predefine ways,.....
Classes: A class is a software component that defines and implements one or more interfaces...A class means collection of methods/functions. Method/function accepts parameters, process set of codes which you have written in the module/function and returns the output to the caller. Collection of class is called Class Library...In other term we can say that a combines data, different function and types, into a new type....
Object: Object are the basic run time entities in object oriented system...They may represent a person, a place a table or any item that program can handle...An object is anything on the form that the user somehow interacts with. For example, a button is an object. You can create a click event for it, and it will execute code....In class , to execute the method and use the properties of the class, we must create an instance of the class, known as object..Creating an instance of a class is referred to as instancing the class...
Creating instance :
DIM call AS NEW A
Here A is the name of class ...New instance is created by using this code...Now CALL has the capability to call any function or procedure within a class...
Classes: A class is a software component that defines and implements one or more interfaces...A class means collection of methods/functions. Method/function accepts parameters, process set of codes which you have written in the module/function and returns the output to the caller. Collection of class is called Class Library...In other term we can say that a combines data, different function and types, into a new type....
- Class module: In visual studio a VB class module is inserted into a project using the ADD class menu item on the project menu...This inserts a new module containing the following code code:
Public Class ClassName...
END CLASS
This is called the class ....End class marks the end of these class definition...Inside this class definition one or many function or procedure can be define which is called at once at the calling point of class..
- Class members: class modules can contain the following types of member...
Data member: This includes member variable and constants..
Event members: Event are procedure that are called automatically by a common language runtime...in response to some action occurs.....
Function member: This refer to both function and subroutine..A function member also called a class...A class constructor is special type of method...
property member: A property member is implemented as a private member together with the special type of VB function that incorporates both accessor function of the property...
Object: Object are the basic run time entities in object oriented system...They may represent a person, a place a table or any item that program can handle...An object is anything on the form that the user somehow interacts with. For example, a button is an object. You can create a click event for it, and it will execute code....In class , to execute the method and use the properties of the class, we must create an instance of the class, known as object..Creating an instance of a class is referred to as instancing the class...
Creating instance :
DIM call AS NEW A
Here A is the name of class ...New instance is created by using this code...Now CALL has the capability to call any function or procedure within a class...
Access specifier...
Access Specifiers describes as the scope of accessibility of an Object and its members. We can control the scope of the member object of a class using access specifiers. We are using access specifiers for providing security of our applications........
Public: The public statement declares element to be accessible from anywhere within the same project, from other project that reference the project, and from an assembly built from the object..... If the variable inside the Public specifier is declared
PUBLIC DIM A AS INTEGER
It means that A variable can be used anywhere outside the class
Private : The scope of the accessibility is limited only inside the classes in which they are declared. The Private members can not be accessed outside the class and it is the least permissive access level....If any variable is define with a keyword private it means that it will be only accessible inside the class in which it is declared.........
Private DIM A AS INTEGER
It means it is only bee accessible its class....
Protected : The scope of accessibility is limited within the class and the classes derived (Inherited )from this class...If any class is inherited with this class can only use.......If any variable is declared with the protected keyword it means that it in only access through its class member function and Derive class member function ,but it cannot be accessed in the class which is not inherited with the base class..
Friend : The Friend access specifier can access within the program that contain its declarations and also access within the same assembly level. You can use friend instead of Dim keyword.
Public: The public statement declares element to be accessible from anywhere within the same project, from other project that reference the project, and from an assembly built from the object..... If the variable inside the Public specifier is declared
PUBLIC DIM A AS INTEGER
It means that A variable can be used anywhere outside the class
Private : The scope of the accessibility is limited only inside the classes in which they are declared. The Private members can not be accessed outside the class and it is the least permissive access level....If any variable is define with a keyword private it means that it will be only accessible inside the class in which it is declared.........
Private DIM A AS INTEGER
It means it is only bee accessible its class....
Protected : The scope of accessibility is limited within the class and the classes derived (Inherited )from this class...If any class is inherited with this class can only use.......If any variable is declared with the protected keyword it means that it in only access through its class member function and Derive class member function ,but it cannot be accessed in the class which is not inherited with the base class..
Friend : The Friend access specifier can access within the program that contain its declarations and also access within the same assembly level. You can use friend instead of Dim keyword.
Constructor....
A constructor is a special member function whose task is to initialize the objects of it's class. This is the first method that is run when an instance of a type is created. A constructor is invoked whenever an object of it's associated class is created. If a class contains a constructor, then an object created by that class will be initialized automatically.... Constructors can never return a value,...In Visual Basic we create constructors by adding a Sub procedure named New to a class....
How to call any constructor:
Dim Himanshu As Family = New Family()
This invokes the default constructor of Family class simply because we have no defined a custom constructor we just define a subroutine name NEW with the class module...
Example:
Class A
Dim x, y, z As Integer
Public Sub New() 'constructor
x = 10
y = 20
z = x + y
End Sub
Public Sub display()
MessageBox.Show("SUM IS:=" & z)
End Sub
End Class
At the calling point:
Dim him As A = New A
him.display()
How to call any constructor:
Dim Himanshu As Family = New Family()
This invokes the default constructor of Family class simply because we have no defined a custom constructor we just define a subroutine name NEW with the class module...
Example:
Class A
Dim x, y, z As Integer
Public Sub New() 'constructor
x = 10
y = 20
z = x + y
End Sub
Public Sub display()
MessageBox.Show("SUM IS:=" & z)
End Sub
End Class
At the calling point:
Dim him As A = New A
him.display()
Q....Inheritance
Inheritance: Inheritance is the property in which, a derived class acquires the attributes of its base class. In simple terms, you can create or 'inherit' your own class (derived class), using an existing class (base class). You can use the Inherits keyword for this. .....Inheritance will allow you to define a very general class(Existing), and then later define more specialized classes (New class) by simply adding some new details to the older . This saves work, because the more specialized class inherits all the properties of the general class and the programmer need only program the new features.
Polymorphism: Polymorphism is the property in which a single object can take more than one form. When you call a function in your object, the system will automatically determine the type of the object to call the appropriate function, if you are assigning an object of the base class to the base class variable, then the function in the base class will work.
In Visual Basic .NET, the Inherits keyword is used to derive a class. Syntax of Inherits keyword looks like this:
Public Class ClassB
Inherits ClassA
End Class
Example:
Calling:
Dim him As New B
him.show()
In the following CLASS B inherits CLASS A ...means it acquires all the property of class B...IN the following example the NUM value in class A is being used by class B
Polymorphism: Polymorphism is the property in which a single object can take more than one form. When you call a function in your object, the system will automatically determine the type of the object to call the appropriate function, if you are assigning an object of the base class to the base class variable, then the function in the base class will work.
In Visual Basic .NET, the Inherits keyword is used to derive a class. Syntax of Inherits keyword looks like this:
Public Class ClassB
Inherits ClassA
End Class
Example:
- Public Class A
- Public num As Integer = InputBox("NUMBER", "HELLO")
- Public Function enter()
- Return num
- End Function
- End Class
- Public Class B
- Inherits A
- Dim i, x As Integer
- Public Function show()
- For i = 1 To 10
- x = num * i
- MessageBox.Show("" & x)
- Next
- Return x
- End Function
- End Class
Calling:
Dim him As New B
him.show()
In the following CLASS B inherits CLASS A ...means it acquires all the property of class B...IN the following example the NUM value in class A is being used by class B
Q....Function overriding???
Function overriding is the method one in which functions have the same name and same type and number of arguments.. But the thing only differs that they are accessed based on the object of the class being called......If the object of the base class is created so it will only call the function of base class....Else if the derive class object is created it will call the the function of the derive class...
Example:
calling point
Dim a As New Child
a.Display()
This will call the class CHILD procedure , since a instance to class Child is created..
Dim a as new parent
a.display()
This will call the PARENT procedure, , since a instance to class parent is created..
Example:
- Public Class Parent
- Public Overridable Sub display()
- MessageBox.Show("From Parent")
- End Sub
- End Class
- Public Class Child
- Inherits Parent
- Public Overrides Sub display()
- MessageBox.Show("From child")
- End Sub
- End Class
calling point
Dim a As New Child
a.Display()
This will call the class CHILD procedure , since a instance to class Child is created..
Dim a as new parent
a.display()
This will call the PARENT procedure, , since a instance to class parent is created..
Q.....My base and my class..
The MyClass keyword behaves like an object variable referring to the current instance of a class as originally implemented. MyClass is similar to Me, but all method calls on it are treated as if the method were NotOverridable....The example is shown below showing
Example my class:
- Class Base
- Public Overridable Sub print()
- messagebox.show("I’m Base")
- End Sub
- Public Sub show()
- MyClass.Print()
- End Sub
- End Class
At calling point
Dim SH as new base
SH.show
The following example will show the text "I'm base" because it is being called with Myclass keyword...
The MyBase keyword behaves like an object variable referring to the base class of the current instance of a class. MyBase is commonly used to access base class members that are overridden or shadowed in a derived class. MyBase.New is used to explicitly call a base class constructor from a derived class constructor.
Example:
- Class Base
- Public Overridable Sub show()
- MessageBox.Show("I’m Base")
- End Sub
- End Class
- Class derive
- Inherits Base
- Public Sub disp()
- MyBase.show()
- End Sub
- End Class
Dim SH as new derive
SH.disp()
Now the MY base keyword is used to call the base class function from derive class....
OVERLOADING?
It is very easy to create a function or procedure in a program within a class..But our requirement needs us to be able to create more members with same names this allows programer to provide easiness to the user by allowing user to use single name for different purposes....For this OVERLOADING method is provided ...Overloading is basically when you have more than one method with the same name but a different number of or different types of parameters. .......
Syntax for overloading:
PUBLIC OVERLOAD SUB HIMANSHU(<ARGLIST>)
END SUB
PUBLIC OVERLOAD SUB(<ARGLIST>)
END SUB
Example:
Syntax for overloading:
PUBLIC OVERLOAD SUB HIMANSHU(<ARGLIST>)
END SUB
PUBLIC OVERLOAD SUB(<ARGLIST>)
END SUB
Example:
- Public Class himanshu
- Dim sum, pro, minus As Integer
- Public Overloads Sub calc(ByVal a As Integer, ByVal b As Integer)
- sum = a + b
- MessageBox.Show("SUM :" & sum)
- End Sub
- Public Overloads Sub calc(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer)
- pro = x * y * z
- MessageBox.Show("PRODUCT IS:" & pro)
- End Sub
- Public Overloads Sub calc(ByVal p As Long, ByVal q As Long)
- minus = p - q
- MessageBox.Show("MINUS:" & minus)
- End Sub
- End Class
USER CONTROL
User Controls are the controls which are created by the user and they are based on the class System.Windows.Forms.UserControl. Like standard controls, user controls support properties, methods and events. Once a user control is created it can be added to any form or any number of forms like all other controls,....In other words we can say that the user control work as a function , like function is created once and can be used many times....Visual basic provide the functionality by adding the user control by the means of drag and drop ...When the user finished creating a user control he can drag and drop in multiple forms when ever it needs....To create a user control in visual basic:
Label1.Text = Today.Date
End Sub
To add user control
- To use user control open visual studio
- Now On the PROJECT MENU select USER CONTROL , and click ADD
- Now USER CONTROL FORM is in front of you is displayed
- Now add the controls according to you need.....Like DRAG AND DROP the LABEL TOOL from the TOOLBOX in the user control form..
- Adjust the size of the USER CONTROL FORM , as the size of the label...
- Now DOUBLE click USER CONTROL FORM and CODE IT TO
Label1.Text = Today.Date
End Sub
- Now BUILD you code by RIGHT click on the solution explorer and select BUILD option.....
- You have successfully created a USER CONTROL
To add user control
- No GO to your form and View the tool box by using the shortcut key Ctrl+ALT+X or select from VIEW
- You will find your user control on the TOOLBOX under WINDOWS APPLICATION COMPONENTS...
- Just Drag and Drop that USER CONTROL to you form....
- You will notice that The following LABEL which is created in the user control form is displayed and the TEXT OF THE LABEL CONTAINS TODAY DATE ...
user.jpg | |
File Size: | 10 kb |
File Type: | jpg |
OLE
A standard for sharing data between applications. . For example, if you cut a picture out of Paint and paste it into a word processor document, you are using OLE to properly put the data into your document...OLE allows objects to be linked to and embedded in other documents. Linking creates a link to the actual object; embedding puts a copy of the object into the document. You can usually access the program an object was created with in order to edit the linked or embedded object just by clicking on the object.....IN visual basic linking provides the link between the one application object into another applications object...If any modification is done in the First application object it will automatically change in the second application object.....Embedding simply do the co[y of the object from one application object to another....If the change is made in the one object , it will not change anything in the other application
COM component object model....
COM stands for component object model ....A software architecture developed by Microsoft to build component-based applications. ...The Component Object Model (COM) is a Microsoft framework for managing component objects, allowing them to communicate by calling methods of other components in their object workspace.....This capability was built into windows 95/98 and window NT 4.0 parts of windows itself ...COM provides the interfaces between object and DCOM distributed com allows them to run remotely ..COM is used in the following.....