Blog 24

Today in the class of Wednesday the 1st of June Todd covered how we split the program up into different tiers, to separate the concerns of our system. This process will be required for our milestone three hand in.

For example any data retained should be stored in a module so that it can be accessed from any form rather than having to be called by each from. So it is a bit like a global variable in that everything can access it.

We put all stuff that connects to data (in test) in class called GameData, in other words paste all the test class code from milestone 2, into a GameData class in the windows forms application for milestone 3 (Because the test class called procedures in the MySQL database).

The GameData is defined inside a module, and when module is run then it creates a publicly available instance of the GameData.

Class Notes:

When coding in the IDE it helps us to write the code, but not structure the program. We want to separate the GUI from the business class, and store persistent data in something called a model, which is just a class named GameData.

We use a method of thinking called N-Tier design-it separating concerns out depending on what they are functioning on.

This architecture imposes a structure or shape on the program your writing. e.g. If code makes something happen in graphical area then put it in the GUI (e.g. frm code).

The business class is the “do something class”. Whenever you want something retained and stored you go to the model, it acts as a store that retains the state. State may just be call to database.

 

For our Milestone 3 we need the model to store PlayerID and GameID, as these are persistent data values that need to be stored, these are pulled out of the database in the GameData class. We call the GameData class from a module with the following code:

Module ModuleGS
Public aGameData As GameData = New GameData()
End Module

The GameData object needs to be rapped inside a module as a GameData so that our project should not have the GameData in each form but in a module instead. Anything  in a module in vb is globally named. You call GameData with GB.

For milestone three we must have Login, select, and show Game working GUI.

So in every program when you have something not specifically related to GUI you place it in business instead. So whenever some action happens in GUI it is stored as event in business tier, as it is not specifically tied to the GUI.

We need to retain state across all parts of program we use a static class, there is only one of these in each application therefore called a singleton. A module is called a singleton. So anything that ephemerally does the work calls the module to get the work done.

We can paste the Test class code from our milestone 2 into a GameData class:

Public Class GameData ‘This is a data object that stores persistent data about GameID and PlayerID
Private _players As List(Of tblplayer)
Private _gameID As Integer = -1
Private _thisPlayer As String
Private db As gamedbEntities = New gamedbEntities()

Public ReadOnly Property Players() As List(Of tblplayer) ‘This gets the players by calling the getPlayers procedure in the MySQL
Get
‘ New everytime
_players = (db.getPlayers()).ToList()

Return _players
End Get

End Property

Public ReadOnly Property GameID As Integer
Get
Return _gameID
End Get
End Property
Public Function RegisterGame() As Integer
_gameID = ((db.regGame()).ToList()).First()
Return _gameID
End Function

Public Sub RegisterPlayer(pGame As String, pName As String, pPass As String)
Dim dummy = db.regPlayer(pGame, pName, pPass)
End Sub

End Class

Project Work:

I had created all the GUI forms for my game in Milestone 1 as screen designs but having looked through all my files and external hard drive backups I cannot find this Visual Studio application and so I will go through creating all the GUI forms again this afternoon.

We must make sure that our VB Windows forms application has the entity reference version 5, before creating the VB application.

When making forms that need to be updated with a timer calling a refreshdata procedure we need to set the form to double buffered=true, so the data grid view does not flicker.

Make a method that encapsulates refreshdata that can be called when form created, and when timer ticks.

So information retained between forms should be put in a module so you can just call the module and it will be available to you inside the application.

 

Note: Property is a pair of methods in a particular syntax  that looks like an attribute

Blog 24

Leave a comment