I have a question about whether it is better to use a unit containing procedures and function or to wrap them in a class as class procedure and function.

I have a question about whether it is better to use a unit containing procedures and function or to wrap them in a class as class procedure and function.

Most of my applications have a unit dedicated to simple functions and procedures that are used through the application but don't really lend themselves to being encapsulated in a class of similar functionality.

Any opinions?

Comments

  1. Attila Kovacs Would you give an example of 'joker' unit/bucket with dependencies... how did you use it? I want to know the experience with flawed design, thanks!

    ReplyDelete
  2. I forever use class methods. Why? I have a unique reason: It's more OOP accurate.

    Sometimes we forget that Delphi comes from an adaptation of the Procedural Language Turbo Pascal. It receives all the things that made it an Object Oriented Language but still conserve "procedural particles" that are really dissonant. Really is a Hybrid Language!

    I know that is a good thing that we don't need to create an Object for every local variable, I agree this inheritance, but when I can, I these things:

    - I always use class methods instead of unit scoped functions.

    - I always delete the global variable that the IDE creates when we create a new form, of the same form class.

    - ...

    Maybe the habit of using another computer languages or maybe a wrong habit, but I like the OOP style.

    ReplyDelete
  3. Attila Kovacs Yes, I used to have a similar "joker" unit where I collected all sorts of generally useful library procedures and functions for my applications and this did start in the old TP days where I knew for sure there was dead code elimination. I'm not sure if the same is true anymore (it should be).

    When I moved all my code to Git from JEDI VCS recently I made the decision to ditch this idea and only have a unit containing the functions that were actually used in the app.

    Everyone else, thanks for the ideas. I think that on further examination some of the code can be grouped into function units/class/record but there are a few which I think for now will remain as is.

    ReplyDelete

Post a Comment