Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, March 29, 2012

Object Orientation Articles?

Can anyone suggest me some good articles on the object orientated programming on the internet? any links would do.
Thanks
Hi,
here you can find an introduction toOOP in VB.NET.
Grz, Kris.

Object Oriented Programming

Hi everybody,
this is nanda kumar,
i want to knowdrawback of objects in oops concepts.
regards,
Nanda kumar. R

Think of OOP as providing services. A method can provide services to many classes and other methods that request it. The main concept behind OOP is reduction of code through code reusability. OOP improves your code by making it more robust. I can't think of anything negitive that OOP presents over traditional procedural programming.


The only drawback I can think of is that it's more difficult to learn (and visualize) than the traditional sequential/structured programming model. Once you become familiar with the concept, it will save you both time and coding.

Thursday, March 22, 2012

Object reference not set to an instance of an object problem

I am a former ASP programmer moving to ASP.Net and object oriented programming.

I am in the process of working on an application where I am going to have a token object, token app, and a page permission object. The token object is going to contain a member id.

Here is the token application


Public Class TokenApp

Private _Token As New Token

Public Function AssignToken(ByVal MemberID As Integer) As Boolean
Dim bnlFlag As Boolean = False

_Token.MemberID = MemberID

If Not _Token Is Nothing Then
bnlFlag = True
End If

Return bnlFlag
End Function

End Class

Here is the token object


Public Class Token

Private _MemberID As Integer

Public Property MemberID() As Integer
Get
Return _MemberID
End Get
Set(ByVal Value As Integer)
_MemberID = Value
End Set
End Property

End Class

And here is the where my problem happens (page permission class).


Public Class PagePermission

Inherits System.Web.UI.Page

Private _PagePermissionLevel As Object

Private oTokenApp As New TokenMainApp.TokenApp
Public oToken As New TokenMainApp.Token

Public Function AssignPagePermission(ByVal PagePermissionLevel As PagePermissionLevel)

oTokenApp.AssignToken(1)

End Function

End Class

Well, I keep getting an "Object reference not set to an instance of an object" error on the line that says "oTokenApp.AssignToken(1)". What am I doing wrong?My guess would be to move this inside the assignToken function but it's just a guess.


Dim Private _Token As New Token

First, what is PagePermissionLevel? Did you intend yourAssignPagePermission function declaration to be:
Public Function AssignPagePermission(ByVal PagePermissionLevel As_PagePermissionLevel) ?

I copied your code into VS.NET and there is no problem with your oTokenApp object and calling the AssignToken method, while passing in a value of "1". I was able to successfully step through your code from start to finish.

I think your problem lies within PagePermissionLevel or there is something you are omitting.

=====================================
Public Class TokenApp
Private _Token As New Token

Public Function AssignToken(ByVal MemberID As Integer) As Boolean
Dim bnlFlag As Boolean = False
_Token.MemberID = MemberID

If Not _Token Is Nothing Then
bnlFlag = True
End If

Return bnlFlag
End Function
End Class

Public Class Token
Private _MemberID As Integer
Public Property MemberID() As Integer
Get
Return _MemberID
End Get

Set(ByVal Value As Integer)
_MemberID = Value
End Set
End Property
End Class

Public Class PagePermission

Inherits System.Web.UI.Page

Private _PagePermissionLevel As Object
Private oTokenApp As New Form1.TokenApp
Public oToken As New Form1.Token

'Public Function AssignPagePermission(ByVal PagePermissionLevel As PagePermissionLevel)

Public Sub AssignPagePermission()
oTokenApp.AssignToken(1)
End Sub

End Class
========================================

-Tom
I forgot to add the enumination

Enum PagePermissionLevel
BasePermission = 1
ProtectedPermission = 2
AdminPermission = 3
End Enum