8 Replies - 434 Views - Last Post: 28 May 2020 - 09:29 AM Rate Topic: -----

#1 blackeagle123   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 124
  • Joined: 28-November 13

Functions for multiple classes

Posted 28 May 2020 - 08:12 AM

Hello Guys i have a question i've been thinking of :
a function is used to not repeat code , what if i need to use the same function in multiple classes ?
to be more clear about what i'm trying to do :
i have multiple classes maybe 2 classes that are gui classes, the functions i need to use are isDate to check if the value in a a textField is a valid date and isNumber to check if it's a valid phone number
what to do in this case sorry if this is a bad question

Is This A Good Question/Topic? 0
  • +

Replies To: Functions for multiple classes

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15724
  • View blog
  • Posts: 62,994
  • Joined: 12-June 08

Re: Functions for multiple classes

Posted 28 May 2020 - 08:31 AM

Yup. I frequently use a 'utility' class that has common, non project specific, functionality I may across solutions.
Was This Post Helpful? 0
  • +
  • -

#3 blackeagle123   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 124
  • Joined: 28-November 13

Re: Functions for multiple classes

Posted 28 May 2020 - 08:35 AM

could you give an example or make it clearer, didn't understand what you meant there
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15724
  • View blog
  • Posts: 62,994
  • Joined: 12-June 08

Re: Functions for multiple classes

Posted 28 May 2020 - 08:39 AM

Type conversion functions, testing output from a a database, time zone conversions, etc. All sorts of helper functions are in one 'utility' class that I can plop into new projects and use.
Was This Post Helpful? 0
  • +
  • -

#5 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Functions for multiple classes

Posted 28 May 2020 - 08:46 AM

Look at the Math class. It has lots of utility methods.
Was This Post Helpful? 2
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15724
  • View blog
  • Posts: 62,994
  • Joined: 12-June 08

Re: Functions for multiple classes

Posted 28 May 2020 - 08:52 AM

That is a stellar example!
Was This Post Helpful? 0
  • +
  • -

#7 blackeagle123   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 124
  • Joined: 28-November 13

Re: Functions for multiple classes

Posted 28 May 2020 - 09:09 AM

so if i got you right i make a new class with the functions i would use in the classes and import the functions every time i need to use them
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15724
  • View blog
  • Posts: 62,994
  • Joined: 12-June 08

Re: Functions for multiple classes

Posted 28 May 2020 - 09:15 AM

Sure. I just copy/paste the utility class file into projects.
Was This Post Helpful? 1
  • +
  • -

#9 blackeagle123   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 124
  • Joined: 28-November 13

Re: Functions for multiple classes

Posted 28 May 2020 - 09:29 AM

thanks for the help guys much appreciated
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1