[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Inheritance, Polymorphism, Interfaces in VB.Net Classes / Nested Classes for ASP.NET

Asked by klm555 in .NET Framework 2.x, Programming for ASP.NET, Microsoft Visual Basic.Net

Tags: Inheritance, Polymorphism, Interfaces, VB, Classes, Nested Classes, ASP.NET

Hi,

I am looking for is mainly some guidance in this subject rather than solving a specific problem presented here. If the examples I have given can be solved, this should help me on my development futher.

I am trying to develop is a self contained object which contains all the properties and classes using inheritance, polymorphism and interfaces.  However, I am running into difficulty setting the object up without causing errors and not being able to have the expected visibilty that I require.

The example I have been working on is based on a Car object, and has various objects including a couple of Doors and a Engine with various properties, methods and attributes.

What I'd like to be able to do with this Car object is a number of things:
      1. Self Contained
                The Door and Engine cannot exist on their own without the Car object. Additionality,  the Door Handle cannot exist without a Door. These objects should be visible when using the IntelliSense when coding the Class.

      2. Reusability
                I have created a Dimension Class and would like to reuse and apply the class to any current/future object created at a later stage which may require these properties. However, if the property is not required. For example, a Windscreen Wiper class requires only a length field, so I can hide the Height and Width properties when creating this object.

      3.  Interfaces
                I have limited the interface of the Class to only what I have provided through the various properties and methods using Interfaces to ensure objects are being using in the right way and call at the level in the object.   For Example, preventing typing source code with a reclusive call like Car.Door.Door.Door.... or being able to call something that doesn't make sense Car.Engine.DoorHandle.

       4. Visiblity
                If I am in a nested class, I should be able to read, but not update any properties of the parent class which I am currently accessing. For example, If I am in the Engine class, I'd like to still be able to see the Year at the Car Class level.

        5. Methods
              I would also like to how to call a method from a class to another class object either or a nested class inside. For example, If I have a Door Handle with a method called Pull(), this function calls a function in the Door object which Opens the door. Similarility, If I have a Fuel Cap Door, the only method aviable would be Push() which opens the fuel cap "Door".

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
<%
	Namespace Cars
	
	Public Class Car
		Implements ICar
		
		Protected oDoorFrontRight, oDoorFrontLeft As IDoor
		Protected oDoorRearRight, oDoorRearLeft As IDoor
		Protected oDoorHood, oDoorBoot, oDoorFuel As IDoor
		Protected oEngine As IEngine
 
		Protected Friend Function Make() As String
			Return strMake
		End Function
 
		Protected Friend Function Model() As String
			Return strModel
		End Function	
 
		Protected Friend Function Year() As Integer
			Return intYear
		End Function		
		Public Sub New()
			oEngine = New CEngine()
			oDoorFrontRight = New Door()
			oDoorFrontLeft = New Door()
			oDoorRearRight = New Door()
			oDoorRearLeft = New Door()
			oDoorHood = New Door()
			oDoorBoot = New Door()
			oDoorFuel = New Door()
		End Sub
		
		Function Running() As String Implements ICar.Running
			Return oEngine.Status
		End Function
		
		Protected Friend Function NumberPlate() As String
		Return "AAA000"
		End Function
		
		Public Interface ICar
			Function Running() As String
		End Interface
		
		Public Interface IDoor
			Property IsOpen() As Boolean
			Sub Close()
			Sub Open()
		End Interface
		
		Public Interface IEngine
			Inherits ICar
			Property HorsePower() As Integer
			Sub StartEngine()
			Sub StopEngine()
			ReadOnly Property Status() As String
			ReadOnly Property StartCount() As String
			ReadOnly Property StopCount() As String
		End Interface
		
		Public Property Boot() As IDoor
			Get
				Return oDoorBoot
			End Get
			Set(ByVal Value As IDoor)
				oDoorBoot = Value
			End Set
		End Property
		
		Public Property Engine() As IEngine
			Get
				Return oEngine
			End Get
			Set(ByVal Value As IEngine)
				oEngine = Value
			End Set
		End Property
		
		Protected Class CEngine
			Inherits Car
			Implements IEngine
			
			Private dblHorsePower As Integer
			Private blnOn As Boolean
			Private intStartCount As Integer = 0
			Private intStopCount As Integer = 0
			
			Property HorsePower() As Integer Implements IEngine.HorsePower
				Get
					Return dblHorsePower
				End Get
				Set(ByVal value As Integer)
					dblHorsePower = value
				End Set
			End Property
			
			Public Sub StopEngine() Implements IEngine.StopEngine
				blnOn = False
				intStopCount += 1
			End Sub
			
			Public Sub StartEngine() Implements IEngine.StartEngine
				blnOn = True
				intStartCount += 1
			End Sub
			
			Public ReadOnly Property Status() As String Implements IEngine.Status
				Get
					Return "The engine is running: " & blnOn & "<br/>"
				End Get
			End Property
			
			Public ReadOnly Property StartCount() As String Implements IEngine.StartCount
				Get
				Return "The engine has been started " & intStartCount & " time(s).<br/>"
				End Get
			End Property
			
			Public ReadOnly Property StopCount() As String Implements IEngine.StopCount
			Get
				Return "The engine has been stopped " & intStopCount & " time(s).<br/>"
			End Get
			End Property
			
		End Class
		
		Protected Class Door
			Implements IDoor
			Protected oDoorhandle As DoorHandle
			
			Private blnOpen As Boolean = False
			
			Property IsOpen() As Boolean Implements IDoor.IsOpen
				Get
					Return blnOpen
				End Get
				Set(ByVal value As Boolean)
					blnOpen = value
				End Set
			End Property
			
		Public Sub Close() Implements IDoor.Close
			blnOpen = False
		End Sub
		
		Public Sub Open() Implements IDoor.Open
			blnOpen = True
		End Sub
		End Class
		
		Protected Class DoorHandle : Inherits Door
			Public Sub Lift()
			Me.Open()
		End Sub
		
		Public Interface IDimensions
		
			Property Height As Double
			Property Width As Double
			Property Length As Double
		
		End Interface
		
		
		Protected Class Dimensions
			Implements IDimensions
			
			dblHeight As Double
			dblWidth As Double
			dblLength As Double
			
			Property Height() As Double String Implements IDimensions.Height
				Get 
					Return dblHeight
				End Get
				Set(ByVal value As Double)
					dblHeight = value
				End Set
			End Property
 
		End Class
		
		End Class
	End Class
	
	End Namespace
 
%>
[+][-]09/15/09 01:16 AM, ID: 25332804Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: .NET Framework 2.x, Programming for ASP.NET, Microsoft Visual Basic.Net
Tags: Inheritance, Polymorphism, Interfaces, VB, Classes, Nested Classes, ASP.NET
Sign Up Now!
Solution Provided By: carl_tawn
Participating Experts: 1
Solution Grade: A
 
[+][-]09/11/09 09:26 AM, ID: 25311088Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/13/09 07:24 PM, ID: 25322706Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 05:22 PM, ID: 25330410Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625