90 likes | 193 Views
CTEC2902 Advanced Programming. Creating & Using Objects. CTEC2902 Advanced Programming. The Story So Far You have been… Doing review exercises in labs & elsewhere Revising year 1 material (essential) Let us carry on…. What is an Object?. Any thing you can define and
E N D
CTEC2902Advanced Programming Creating & Using Objects
CTEC2902Advanced Programming • The Story So Far • You have been… • Doing review exercises in labs & elsewhere • Revising year 1 material (essential) • Let us carry on…
What is an Object? Any thing you can define and interact with in your program To create objects … Dim object_name As New class_name e.g., Dim dtSales As New DataTable You can now use dtSales to process data, using all features of DataTable
Creating & Using Objects Question: What service does a class provide? How do I create instances of the class? What are its properties and methods? How can I use its services? Answer: you need to read the API of the class
clsPerson Class Exercises • Create 3 objects, named Zoe, Jay, and Joe • Dim Zoe As New clsPerson • Dim Jay As New clsPerson • Dim Joe As New clsPerson
Properties To refer to a property Object.property_name Remember: properties behave like variables So, set or get values • e.g. to set values • Zoe.FirstName = “Zoe” • Zoe.Surname = “Smith” • Jay.DoB = #01/04/1995# • Joe.Gender = “M” e.g. to get values txtName.Text = Zoe.Surname lblBirthDate.Text = Zoe.Dob e.g. also … Zoe.DoB = Jay.DoB Joe.Gender = Jay.Gender
Methods Remember: methods behave like functions So, consider parameters To refer to a method Object.method_name() • e.g. Show Zoe’s age on screen • lblAge.Text = Zoe.Age() • txtName.Text = Jay.FullName()
Essential Revision • In your own time ... • Review these slides • Make sure you understand properties and methods
More on objects next week