sexta-feira, 4 de setembro de 2020

DICAS 3066 -WINDEV TUTORIAL 89 -Licao 7.9-12-09-2020 11hrs-The OOP





https://youtu.be/ou6IdHeF1e8


Bom Dia/Boa Tarde/Boa Noite

Esse Ao Vivo vai estrear as 11:00 do dia 12/09/2020 

DICAS 3066 -WINDEV TUTORIAL 89 -Licao 7.9-12-09-2020 11hrs-The OOP
Tutoriel WINDEV : Leçon 7.9. Programmation avancée - La POO


ASSUNTOS
..
OOP - CONCEITOS
CLASSES
OBJETOS
MEMBROS
METODOS 
HENRANCA 
CONTRUTOR E DESTRUTOR
EXEMPLO
DECLARANDO 
DIAGRAMA UML
DESPEDIDA DO TUTORIAL 


Video original da Franca
https://youtu.be/dezl--vdqbM


Playlist Windev Tutorial Amarildo
Playlist windev Franca PcSoft
Amarildo
Windev
WxSolucoes
Matos Informatica
Repositorio Windev
Site forum Google 
Video sobre 3 Mil Videos Windev 
PlayList Pedrosao
Video sobre Alfaserver servidor 

DICAS 2979 - WINDEV TUTORIAL 2 - 1.2- CRIAR JANELA E INSERIR TEXTO E EXIBIR
DICAS 2980 - WINDEV TUTORIAL 3 - 2.1- VARIAVEIS PARTE 1
DICAS 2981 - WINDEV TUTORIAL 4 - 2.2- VARIAVEIS ESCOPO - PARTE 2
DICAS 2982 - WINDEV TUTORIAL 5 - 2.1- VARIAVEIS OPERADORES PARTE 3
DICAS 2983 - WINDEV TUTORIAL 6 - 2.1.D - VARIAVEIS STRINGS PARTE 4
DICAS 2984 - WINDEV TUTORIAL 7 - 2.1.E - VARIAVEIS ARRAYS PARTE 5
DICAS 2985 - WINDEV TUTORIAL 8 - 2.2.A - CONDICOES IF-SWITCH PARTE 1
DICAS 2986 - WINDEV TUTORIAL 9 - 2.2.B - CONDICOES PARTE 2
DICAS 2987 - WINDEV TUTORIAL 10 - 2.3.A - LOOP PARTE 1
DICAS 2988 - WINDEV TUTORIAL 11 - 2.3.B - LOOP EXEMPLOS PARTE 2
DICAS 2989 - WINDEV TUTORIAL 12 - Lesson 2.4. The procedures - PARTE 1
DICAS 2990 - WINDEV TUTORIAL 13 - Leçon 2.4.b. Procedures Parametros - PARTE 2
DICAS 2991 - WINDEV TUTORIAL 14 - PROCEDURES REFERENCIA - PARTE 3
DICAS 2992 - WINDEV TUTORIAL 15 - PROCEDURES OPCIONAIS OU OBRIGATORIAS - PARTE 4
DICAS 2993 - WINDEV TUTORIAL 16 - PROCEDURES EXEMPLOS - PARTE 5
DICAS 2994 - WINDEV TUTORIAL 17 - PERGUNTAS E RESPOSTA - PARTE 1
DICAS 2995 - WINDEV TUTORIAL 18 - PERGUNTAS E RESPOSTA - PARTE 2
DICAS 2996 - WINDEV TUTORIAL 19 - WINDEV E OS BANCOS DE DADOS
DICAS 2997 - WINDEV TUTORIAL 20 - PROJETO E ANALISE - CRIACAO
DICAS 2998 - WINDEV TUTORIAL 21 - PROJETO E ANALISE - ARQUIVOS DADOS CLIENTE - PARTE 2
DICAS 2999 - WINDEV TUTORIAL 22 - PROJETO E ANALISE - ARQUIVOS DADOS CRIACAO ARQUIVO PEDIDO - PARTE 3
DICAS 3000 - WINDEV TUTORIAL 23 - PROJETO E ANALISE - IMPORTANDO CVS-ARQUIVO TEXTO - PARTE 4
DICAS 3001 - WINDEV TUTORIAL 24 - PROJETO E ANALISE - IMPORTANDO ARQUIVO PRODUTO - PARTE 5
DICAS 3002 - WINDEV TUTORIAL 25 - PROJETO E ANALISE - LINK - PARTE 6
DICAS 3003 - WINDEV TUTORIAL 26 - RAD COMPLETO
DICAS 3004 - WINDEV TUTORIAL 27 - VISAO GERAL
DICAS 3005 - WINDEV TUTORIAL 28 - Adicionar e Modificar Janelas PRODUTOS - PARTE A
DICAS 3006 - WINDEV TUTORIAL 29 - Adicionar e Modificar Janelas PRODUTOS Formulario - PARTE B
DICAS 3007 - WINDEV TUTORIAL 30 - Adicionar e Modificar Janelas PRODUTOS ALINHAR CAMPOS - PARTE C

















Lesson 7.9. The OOP
This lesson will teach you the following concepts
  • Concepts of Object-Oriented Programming.
  • Examples of object declaration.
  • Associated UML model.
Lesson duration

Estimated time: 30 mn
Previous LessonTable of contentsNext Lesson
Concepts
Object-Oriented Programming (OOP) is designed for better code reusability. The programs developed in OOP are structured: they include modules, each one managing a software feature. These modules can easily be re-used in other software. They group a set of procedures (called methods) and they encapsulate the data structure on which the methods will act.
To use object-oriented programming, you must declare classes, members and associated methods.

The classes

class contains the description of a data structure (the members) and the procedures (methods) that handle the members.
Therefore, a class defines a type of data and its behavior.

The objects

A class is used to create objects. Each created object owns the members described in its class and it can be handled via the methods of its class. An object is defined as a class instance.
When the class is declared, all you have to do is associate an object with a class in order for the object to be handled by all methods of this class.

The members

member is a data (or parameter) of the object.

The methods

method is used to act on the object, to modify its members for example.
A method is a procedure. Its operating mode is similar to the one of standard WLanguage procedures.

Concept of inheritance

The inheritance is used to include the characteristics of an existing class (base class) into a new class (derived class). The inheritance allows you to create a new data type from a known type in order to add features to it or to modify its behavior. Therefore, the base class will not be modified. A class can inherit from a class: it becomes a sub-class of this class.
The objects found in a derived class can access all methods, all members and all properties of ancestor classes; it is as if the methods, the members and the properties of ancestor classes were part of the derived class.

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").
Simple example
  • To illustrate these concepts, we will use the example named "WD Simple OOP".
    1. Open the training example named "WD Simple OOP".
    2. Run the test of this example.
      WD OOP Simple example
    3. Click the different buttons corresponding to the animals in order to add them.
    4. Stop the example test to go back to the editor.Remark: We won't go into details about the syntax of OOP but we will present a simple example of an object-oriented program.

See Classes, members, methods and properties for more details.

Declaring a class

  • WINDEV allows you to easily declare the classes from the "Project explorer" pane. To create a class:
    1. In the "Project explorer" pane, select the "Classes" folder
    2. Display the popup menu of this folder (right mouse click) and select "Create a class".
    3. In the window that is displayed, specify the class name ("TestTUT" for example) and validate.
  • Study the WLanguage code of cSavanna class used in the example.
    1. In the "Project explorer" pane, select the "Classes" folder
    2. Open the "Classes" folder (to do so, click the arrow found in front of the folder name).
    3. Double-click the cSavanna class.
    4. The class WLanguage code is displayed in the code editor. The declaration code of the class is as follows:
      cSavanna is Class
       
      PROTECTED
      // Name of Image control used for the drawing
      m_sNameImageControlForDrawing is string
      // List of savanna animals
      m_arrTheAnimals is array of cAnimal dynamic
      END
      In this code:
      • "cSavanna" is the class name.
      • "m_sNameImageControlForDrawing" and "m_arrTheAnimals" are class members.
      • The "PROTECTED" keyword is used to specify that these members can only be handled from a code of the class or from a code of a derived class.

Describing the methods

  • WINDEV allows you to easily declare the classes from the "Project explorer" pane. To create a method:
    1. Right-click your class in the "Project explorer" pane.
    2. Select "New method" from the popup menu.
    3. In the window that is displayed, specify the method name and validate.
    4. Type the method code in the code editor.
  • To display the AddAnimal method of cSavanna class:
    1. Click your class in the "Project explorer" pane.
    2. Click the little arrow found in front of the class name: the different class methods are displayed.
    3. Double-click the method name:
      PROCEDURE AddAnimal(pclAnAnimal is cAnimal dynamic)
       
      // No more than 5 animals
      IF m_arrTheAnimals..Count = 5 THEN
      Error("No more than 5 animals!")
      RESULT False
      END
       
      // Adds the animal to the list
      Add(m_arrTheAnimalspclAnAnimal)
       
      // Draws the savanna
      DrawSavanna()
       
      RESULT True

Declaring and handling the objects

In the window WLanguage events, an object is declared at the same time as the other variables:
// Global declarations of WIN_OOP
PROCEDURE WIN_OOP()
 
// Savanna object
gclTheSavanna is cSavanna(IMG_Landscape..FullName)
To refer to a member of "cSavanna" object, use the following syntax
<ObjectName>.<member name>
  • In our example, the object is handled:
    • in the "Initializing" event of the window, to build the savanna.
      // Draws the savanna
      gclTheSavanna.DrawSavanna()
    • When creating an animal, to position the animal in the savanna.
      // Declares a new elephant
      clElephant is cElephant("Elephant "GetIdentifier(), 13)
       
      // Adds the elephant into the savanna (this action refreshes the drawing)
      IF gclTheSavanna.AddAnimal(clElephant) THEN
      // End message
      ToastDisplay("Animal added"toastShortvaMiddlehaCenter)
       
      END
We won't go into details about OOP in this tutorial.
UML diagram
The "WD Simple OOP" example is associated with an UML diagram.
  • To display the UML diagram linked to the project:
    1. Double-click "UML model" in the "Project explorer" pane:
      'Project explorer' pane
    2. The UML diagram (class diagram) linked to the project is displayed.
      UML diagram
    3. The different classes used by the "WD Simple OOP" project are found in this diagram.

Remark

WINDEV allows you to create the 9 types of UML diagrams.
To create a UML diagram:
  1. On the "Home" pane, in the "General" group, click "New".
  2. The element creation window appears: click "Architecture" then "UML".
  3. The UML model creation wizard starts, allowing you to choose the model to create:
    UML diagram creation wizard
We won't go into details about the use of UML language with WINDEV.
See The UML model for more details).




Nenhum comentário:

Postar um comentário

Teste

Teste
teste