Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Classes and Controls CE-105 Spring 2007 By: Engr. Faisal ur Rehman.

Similar presentations


Presentation on theme: "1 Classes and Controls CE-105 Spring 2007 By: Engr. Faisal ur Rehman."— Presentation transcript:

1 1 Classes and Controls CE-105 Spring 2007 By: Engr. Faisal ur Rehman

2 2 Class Class is a template, from which objects can be instantiated Class  Object Just like: Blue print  Building Stencil  Shapes and letters Cookie cutter  Cookies It is used in Object Oriented Programming

3 3 Class OOP is a programming technique in which code block is considered as objects of real world

4 4 Benefits of Class OOP enables: 1. Managing big applications 2. Modifying the code with ease 3. Code is organized properly 4. Updating of the applications 5. Encapsulation: Encapsulation is the ability to contain and control access to a group of associated items. Only methods and properties of a class is available for other programmers to use. It is just like a remote control or Black Box programming 6. Create more flexible applications

5 5 Components of Class Components are: Fields: Variables used by the class Property: Attributes of an object Methods: Action by the object Events: Response to some action like click

6 6 Property Code Property code is created easily with snippet Following is read-write property: Private newPropertyValue As Integer Public Property NewProperty() As Integer Get Return newPropertyValue End Get Set(ByVal value As Integer) newPropertyValue = value End Set End Property

7 7 Method Code Method is a Sub or Function in a class. Following code will add method to a function class Public Function FullName() As String If middleNameValue <> "" Then FullName = firstNameValue & " " & middleNameValue & " " _ & lastNameValue Else FullName = firstNameValue & " " & lastNameValue End If End Function

8 8 Terms Of Class Constructors: Special methods that execute each time a new instance of a class (an object) is created Public sub new ‘set default values to fields end sub

9 9 Terms Of Class Shared methods: Shared method does not need initialize of class. Instance Method: Needs initialize of a class e.g., math.sin is a shared method as we use it directly without instantiate of math class Form1.Show is Instance method as it need instantiate of form class

10 10 Terms Of Class Inheritance Class will derive its attributes and functionality from base class and specialize the base class by adding new properties and methods and override properties and methods The Inherits statement is used to declare a new class, called a derived class, based on an existing class, known as a base class. Classes that serve as a basis for new classes are called base classes. Classes derived from base classes are called derived classes. Use protected keyword for fields to make available to derived class

11 11 Class Practical In MSDN: “Modeling a Real World Object”

12 12 Controls Controls are objects with visual interface with input / output capability We can make a customized control based upon set of existing controls Further Reading: In MSDN: “Developing Custom Windows Forms Controls with the.NET Framework”

13 13 Q & A Define Class List benefits of class Define the following terms: –Encapsulation –Static / Shared method –Instance method –Constructor –Inheitence

14 14


Download ppt "1 Classes and Controls CE-105 Spring 2007 By: Engr. Faisal ur Rehman."

Similar presentations


Ads by Google