Real Time Interface Explanation - 2
UI
|
MySQL Class
|
Sql Class
|
Business Layer
|
Data Layer
|
Interface
|
Oracle Class
|
If application needs to switch between Database Engine
and Each Database Engine Class is different and Managed by Different Team.
Managing Data Layer will be difficult. As if one team adds one method or
changes parameter for one method same has to be maintained in others. To manage
consistence. Interfaces are used.
Form
/Page
Dim
C1 as new cSQLServer [This is object
of Class database Engine]
Dim
iDEng as new iDEngine [This is object
of interface]
Load
event
iDEng
= C1
Save
event and other event
[Once
Interface linked to object of class further interface used in page/Form]
iDEng.Validate
iDEng.Save
Note
:- Now With Current example if Sqlserver Engine class is used and Oracle team
member has added new method and same is missing in Sqlserver than when Module
is switched to sqlserver it will give runtime or compile time error
To
manage this issues Interface is used Once added in interface it will always
required in all the class which is implemented it this way it will help to
manage inconsistency between class which are not dependent but are to used
P.T.O: Check for Parameter Passing Concept of
Interfaces
Public Class Form1
'One more
Advantage of having interface is. When you need Method with Class Object as
Parameter and you have two different classes than either you need to create two
methods with different Parameter and repeat you’re working. But with interface
is simple. Just have interface as Parameter and use same interface in both
class. It will take the Object of any Class which is having that interface.
'Button1
: Is Sending Object C1 and C2 to Check Value Method were Parameter is Interface
IProperties
Private Sub
Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim C1 As New C1
Dim C2 As New C2
C1.P2 = True
C2.P2 = False
CheckValue(C1)
CheckValue(C2)
End Sub
Private Sub
Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
Dim C1 As New C1
Dim C2 As New C2
Dim IP As IProperties
C1.P2 = True
IP = C1
'IP.P1 =
True 'This will not work
CheckValue(IP)
C2.P2 = False
IP = C2
CheckValue(IP)
End Sub
Private Sub
CheckValue(Value As IProperties)
Dim x As Boolean = Value.P2
MessageBox.Show(x)
End Sub
End Class
Public Interface IProperties
Property P1 As Boolean
Property P2 As Boolean
End Interface
Public Class C1
Implements IProperties
Public Property P1 As Boolean Implements IProperties.P1
Public Property P2 As Boolean Implements IProperties.P2
End Class
Public Class C2
Implements IProperties
Public Property P1 As Boolean Implements IProperties.P1
Public Property P2 As Boolean Implements IProperties.P2
Public Property P3 As Boolean
End Class
Comments
Post a Comment