Single File for Multiple Class?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Single File for Multiple Class?

Post by yetneverdone »

Hi, I am using the OOP Library "classic", I created a single "item" class as a base class for many more classes like "cabinet", "crib, "toys", etc.

I was wondering if I can just use a single file that will contain all of the children class. It seems inconvenient if i will create a file for each class.
Fuzzlix
Citizen
Posts: 60
Joined: Thu Oct 13, 2016 5:36 pm

Re: Single File for Multiple Class?

Post by Fuzzlix »

yetneverdone wrote:Hi, I am using the OOP Library "classic", I created a single "item" class as a base class for many more classes like "cabinet", "crib, "toys", etc.

I was wondering if I can just use a single file that will contain all of the children class. It seems inconvenient if i will create a file for each class.
Its a question of your personal style. For löve it really doesnt matter, it becomes zipped to a single .love file anyway.
But sometimes it is usefull to glue all sources into a single .lua file. In this case i do a package preloading in my main lua source file like:

Code: Select all

package.preload["classic"] = function(...) 
  -- module source here.
  ..
end;
This solution is nice for code folding editors too.
User avatar
Sheepolution
Party member
Posts: 264
Joined: Mon Mar 04, 2013 9:31 am
Location: The Netherlands
Contact:

Re: Single File for Multiple Class?

Post by Sheepolution »

I recommend making a file for each class, no matter how small. This way your code looks a lot more organized and you can navigate your classes easier.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests