Tuto WINDEV 25
Part 7: Advanced programming 427 Constructor and Destructor The notions of Constructor and Destructor are important because they allow for an automatic call to initialization methods when creating an object and when destroying it. The Constructor method associated with a class is automatically called when declaring a class object. The Destructor method associated with a class is automatically called when deleting the object (exit from the procedure where the object was declared). Data encapsulation The data encapsulation is used to ensure that the data belonging to the object is not accidentally modified by functions (methods) external to the object. This allows you to prevent the user of an object from accessing some or all of its members. The members whose access is forbidden are called private members. These private members can only be accessed from the methods designed for this purpose in the class. Example Let’s take a simple example to apply these concepts: • Let’s consider the PERSON class. • Florence is an instance of PERSON class. • The last name, first name and date of birth can be members of PERSON class. • The Age() method can be a method of PERSON class. It would calculate the age according to the "date of birth" member and according to todays’ date (returned by DateSys ). • Inheritance: A contact can be either a person, or a company. • PERSON could be a class derived from CONTACT. • COMPANY could be a class derived from CONTACT. Creating an object-oriented program To create an object-oriented program in WLanguage, you must: 1. Describe the class and the class members 2. Specify all class methods. 3. Declare the objects by associating them with a class ("instantiate a class").
Made with FlippingBook
RkJQdWJsaXNoZXIy NDQ0OA==