I picked up programming after a five years absence and just made my first app with VS2005. Though I did use as much as from the .dot framework as possibly could, the code is more classical VB in that I have a module and lots of functions and Subs.

Now I'm rewriting the app, the OOP way. So I'm struggling with classes and such

My app basicly scans any folders the user selected for files of certain types.
If it is of the type I want, I want to 'Collect' it.

I made a class for the type i want, containing some properties and methods.

The one thing I'm not certain of is when I want to collect a file (ie add it),
should I add it to a collection of some sort within the class OR should I add an instance of the class for that file to an collection outside the class, ie een collection of objects?


Here's the code for the class (not finished yet):

VB Code:
  1. Public Class MyMovie
  2.     Private strMovie As String
  3.     Private SubExtensions() As String = {".srt", ".sub"}
  4.     Private arrBadWords() As String = {}
  5.  
  6.     Public Sub New(ByVal FullMovieName As String)
  7.         strMovie = FullMovieName
  8.         arrBadWords = BadWords()
  9.     End Sub
  10.  
  11.     Public ReadOnly Property Name() As String
  12.         Get
  13.             Return My.Computer.FileSystem.GetFileInfo(strMovie).Name.ToString
  14.         End Get
  15.     End Property
  16.  
  17.     Public ReadOnly Property Folder() As String
  18.         Get
  19.             Return My.Computer.FileSystem.GetFileInfo(strMovie).Directory.FullName
  20.         End Get
  21.     End Property
  22.  
  23.     Public Function IsMovie() As Boolean
  24.         'TO DO
  25.     End Function
  26.  
  27.     Public Function HasSubs() As Boolean
  28.         Dim strExt As String
  29.         Dim strMovieExt As String = strMovie.Trim.Substring((strMovie.Trim.Length) - 4, 4)
  30.         Dim strSub As String = strMovie.Trim.Substring(0, (strMovie.Trim.Length) - 4) 'strip extension
  31.  
  32.         'is there a file with the same name and a sub extension ?
  33.         For Each strExt In SubExtensions
  34.             If System.IO.File.Exists(strSub & strExt) Then
  35.                 Return True
  36.                 Exit Function
  37.             End If
  38.         Next
  39.         Return False
  40.     End Function
  41.  
  42.     Public Function CleanName() As String
  43.         (...)
  44.         Return strMovie
  45.     End Function
  46.  
  47.     Private Function BadWords() As Array
  48.         'Set the user defined "Bad Words" List
  49.         'When a custom list is saved it is loaded into table "BadWords" during startup (LoadSettings())
  50.         'If the list is empty populate with hardcoded list
  51.         Dim tbl As DataTable = frmMain.dsProgramSettings.Tables.Item("BadWords")
  52.         Dim row As DataRow
  53.         Dim item As String
  54.         Dim i As Short
  55.         Dim arrList() As String = {"divx", "xvid", "dvdrip", "dvdscr", "ws", "done", "dvd", "rip"}
  56.  
  57.         If tbl.Rows.Count > 0 Then 'repopulate array list
  58.             ReDim arrList(tbl.Rows.Count - 1)
  59.             For i = 0 To UBound(arrList)
  60.                 arrList(i) = tbl.Rows(i).Item("Word").ToString
  61.             Next
  62.         Else 'Populate dataset table
  63.             For Each item In arrList ' fill datatable
  64.                 row = tbl.NewRow
  65.                 row("Word") = item.ToString.ToLower
  66.                 tbl.Rows.Add(row)
  67.             Next
  68.         End If
  69.  
  70.         Return arrList
  71.  
  72.     End Function
  73.  
  74. End Class