Another decision about whether to use properties or functions is to instantiate the parent object. VB has surprisingly convenient syntax, for example.
Dim MyStudent as Student With {.Name = "Bobby", .Age = 10}
In section "C" only properties are available.
I support an application with many stored objects in a database in which there are many relationships between objects. for example, the student has a teacher, and the teacher moved to the database.
I usually use the WriteOnly property to set Teacher, since this is a backlit operation, but if there is a potentially expensive access to the database to retrieve Teacher, I use the retrieve function. In other words:
Public Writeonly Property Teacher() as Teacher Public Function GetTeacher() as Teacher
This allows me to create a Student instance in the form With {.Teacher = SomeTeacherObject} , but GetTeacher recommends caching the Teacher object in the user code, and not just use it as a property that may or may not lead to several DB access calls.
If anyone has comments on this approach, I would love to hear them.
source share