Created
April 21, 2016 17:29
-
-
Save jpartogi/4e1ed9a5f0a08ad9ff15c953cf6f5869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class BankAccount | |
Public Sub New(AccountNumber As String) | |
Me.AccountNumber = AccountNumber | |
End Sub | |
Public Property AccountNumber() As String | |
Get | |
Return m_AccountNumber | |
End Get | |
Private Set | |
m_AccountNumber = Value | |
End Set | |
End Property | |
Private m_AccountNumber As String | |
Public Property AccountBalance() As Double | |
Get | |
Return m_AccountBalance | |
End Get | |
Set | |
m_AccountBalance = Value | |
End Set | |
End Property | |
Private m_AccountBalance As Double | |
Public Property Interest() As Double | |
Get | |
Return m_Interest | |
End Get | |
Private Set | |
m_Interest = Value | |
End Set | |
End Property | |
Private m_Interest As Double | |
Private Const InterestRate As Double = 5.5 | |
' calculating interest business logic | |
Public Sub CalculateInterest() | |
Interest = (InterestRate * AccountBalance) / 100 | |
End Sub | |
Public Sub SaveMoney(amount As Double) | |
AccountBalance = AccountBalance + amount | |
End Sub | |
Public Sub WithdrawMoney(amount As Double) | |
AccountBalance = AccountBalance - amount | |
End Sub | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class Shape | |
Const CIRCLE As Integer = 1 | |
Const RECTANGLE As Integer = 2 | |
Private TYPE As Integer = 0 | |
Private radius As Double | |
Private width As Double | |
Private length As Double | |
Public Function Area() As Double | |
Select Case TYPE | |
Case CIRCLE | |
Return Math.PI * radius | |
Case RECTANGLE | |
Return width * length | |
Case Else | |
Return 0 | |
End Select | |
End Function | |
Public Sub CreateCircle(radius As Double) | |
Me.radius = radius | |
Me.TYPE = CIRCLE | |
End Sub | |
Public Sub CreateRectangle(length As Double, width As Double) | |
Me.width = width | |
Me.length = length | |
Me.TYPE = RECTANGLE | |
End Sub | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Interface IShape | |
Function Area() As Double | |
End Interface | |
Public Class Rectangle | |
Implements IShape | |
Public Property width() As Double | |
Get | |
Return m_width | |
End Get | |
Set | |
m_width = Value | |
End Set | |
End Property | |
Private m_width As Double | |
Public Property length() As Double | |
Get | |
Return m_length | |
End Get | |
Set | |
m_length = Value | |
End Set | |
End Property | |
Private m_length As Double | |
Private Sub New() | |
End Sub | |
Public Sub New(width As Double, length As Double) | |
Me.width = width | |
Me.length = length | |
End Sub | |
Public Function Area() As Double Implements IShape.Area | |
Return Me.width * Me.length | |
End Function | |
End Class | |
Public Class Square | |
Inherits Rectangle | |
Public Sub New(edge As Double) | |
MyBase.New(edge, edge) | |
End Sub | |
Public Property edge() As Double | |
Get | |
Return m_edge | |
End Get | |
Set | |
m_edge = Value | |
End Set | |
End Property | |
Private m_edge As Double | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Interface Vehicle | |
Sub Fly() | |
Sub Drive() | |
End Interface | |
Public Class Car | |
Implements Vehicle | |
Public Sub Drive() Implements Vehicle.Drive | |
'Implement drive here | |
End Sub | |
Public Sub Fly() Implements Vehicle.Fly | |
Throw New Exception("Can not fly") | |
End Sub | |
End Class | |
Public Class Plane | |
Implements Vehicle | |
Public Sub Drive() Implements Vehicle.Drive | |
Throw New Exception("Not a good idea") | |
End Sub | |
Public Sub Fly() Implements Vehicle.Fly | |
'Implement fly here | |
End Sub | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Interface IOutputter | |
Sub Print(output As String) | |
End Interface | |
Public Class ConsoleOutputter | |
Implements IOutputter | |
Public Sub Print(output As String) Implements IOutputter.Print | |
System.Console.Write(output) | |
End Sub | |
End Class | |
Public Class MockOutputter | |
Implements IOutputter | |
Public Sub Print(output As String) Implements IOutputter.Print | |
End Sub | |
End Class | |
Public Class CommandInvoker | |
Public Sub Invoke(outputter As ConsoleOutputter) | |
outputter.Print("Hello World") | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment