CODESYS - Runtime polymorphism using inheritance (OOP)

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ต.ค. 2024

ความคิดเห็น • 12

  • @johnmhedges
    @johnmhedges ปีที่แล้ว

    Hi there,
    Geat videos! I've not used interfaces or inheritance in my projects before.
    What is the advantage of using this type of implementation versus simply creating specific functions or funtion blocks? For example, just having a function for calculating area each shape and returning a result.

    • @atu1330
      @atu1330  ปีที่แล้ว +3

      For me personally there are some reasonable reasons.
      1. An interface / abstract class allows you to guarantee that certain methods exist and return the required types. When the compiler knows this, it can use that assumption to work with unknown classes as if they had certain known behavior.
      2. If the classes C, D, E,… implement an interface or inherit a abstract base class AI, you can use a C, D, E,… whenever an AI is expected. Simple example is the function that returns the area of a shape. The function does not care what kind of shape it is passed to it, but if it’s a shape, it will calculate its area. When you don’t have an interface you have to have a explicit function for every shape, in other words, where C is expected you can‘t pass D, you can only pass C. So you need the explicit shape.
      3. If you use an abstract class, you can have explicit methods with a default implementation, that are provided to all children classes. Let’s say as an example the calculation of all shape areas is very heavy and complicated. For these we should provide some common functionalities to help us with the calculation. We can create some concrete methods (the common functionalities) and use these methods for the calculation of every area in every child class, you don’t need to copy/paste those to every new function block (circle, triangle….) or break the encapsulation of a class. In simple words, when you provide the concrete methods in the base class, all child classes can have their own implementation of the area, but use the common methods of the base class without having to define those for every shape.
      4. You will have a better code maintainability.

    • @johnmhedges
      @johnmhedges ปีที่แล้ว +1

      @@atu1330 That's very helpful to know! Thanks for taking the time to explain further 😊

  • @7Denial7
    @7Denial7 11 หลายเดือนก่อน

    Maaan thank you very Much, the video is sublime!!! It's a surprise for me that it's possible to write program for PLC's in a full-blown OOP style!!!

  • @Runtimevic
    @Runtimevic 2 ปีที่แล้ว +1

    very good, if you could host it somewhere it would be very good, to be able to have the example projects ...
    Thanks for everything.

    • @atu1330
      @atu1330  2 ปีที่แล้ว +1

      Hey Victor, thanks for your suggestion. I’m gonna create a git repository and you will be able to download the source code from the videos. Please have some patience until I am able to do it.

    • @Runtimevic
      @Runtimevic 2 ปีที่แล้ว

      @@atu1330, thanks you 👍🏻😉

    • @Runtimevic
      @Runtimevic 2 ปีที่แล้ว

      @@atu1330, thanks you

    • @Runtimevic
      @Runtimevic 2 ปีที่แล้ว

      @@atu1330 , have you had time to create the repository?,
      thank you very much for everything...

    • @atu1330
      @atu1330  2 ปีที่แล้ว +1

      Hey Victor, you can find some of the programs in the repositories. All the projects are saved as Archive.
      github.com/ATandU?tab=repositories

  • @dexterfoley2701
    @dexterfoley2701 2 ปีที่แล้ว +1

    Decent this is!! This channel needs P R O M O S M!