I have been a VB developer for couple of years, but strictly using functional programming paradigms — I just started using object-oriented paradigms a few days ago, and want some advice on how to improve.
I'm writing a small calculator application in order to understand VB.NET object-oriented principles. The program is (currently) working perfect the way I've done it (following some books and tutorials), and I want to get some response on how I'm doing regarding following OOP principles, paradigms and practices.
The program flow is pretty simple, and as follows:
- The user enters the first number to add;
- The user enters the second number to add;
- The user clicks on the "calculate" button;
- The UI (through
Label2) updates to show the result;
The code is mostly done through the main class
Public Class Cls_addition 'Variable de Classe Private term1 As Integer Private term2 As Integer Private resultat As Long 'Properties Public Property termA() As Integer Get Return term1 End Get Set(ByVal value As Integer) term1 = value End Set End Property Public Property termB() As Integer Get Return term2 End Get Set(ByVal value As Integer) term2 = value End Set End Property 'Methods Public Function additioner(ByVal term1 As Integer, ByVal term2 As Integer) As Long resultat = term1 + 0 + term2 Return resultat End Function End Class Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim totalAddition As New Cls_addition 'Creation d'un obejct (creation nouvelle instance d'un obeject a l'aide du mot clé "New") totalAddition.termA = TextBox1.Text.Trim 'Object.Proprieté totalAddition.termB = TextBox2.Text.Trim 'Object.Proprieté Label2.Text = totalAddition.additioner(totalAddition.termA, totalAddition.termB) End Sub
And I have also attached a picture of the form itself: