Skip to main content

Posts

Showing posts with the label database-design

Object Oriented Programming: More than just basic objects

I seem to find all documentation regarding OOP too basic or too advanced. I'm trying to solve a specific problem and I can't get a nice solution without having to use Singletons or global instances or the such. I'm trying to create a DB based application: I have a DB with Boxes that are stored in some Location. So I created to tables: Boxes and Locations BOXES | id | Name | Location | ------------------------ | 1 | AA | 1 | | 2 | AB | 2 | LOCATIONS | id | Name | --------------------- | 1 | Garage | | 2 | Living Room | When trying to bring this to an Java application, I want to have a Box class that I can instantiate for every box and locations that I have in DB and put them in a list. My question is: how do I design Box and Location Classes? The immediate approach would be: class Box { int id; String name; Location location; } Class Location { int id; String name; } But then, how can I operate Locations properly?

PHP/MySQL - store default text in database or in a file?

OK so I am creating a system where whenever a shop signs up, they get 10 default slides that they can then customize later. The default slide data is just a starting point for them. But I have to assume a lot of shops will not log in and update the information, they just want something up ASAP. So say for the Dashboard slide, every shop starts out with the same heading and text until they go in and update it themselves. Do I insert it in the database, like so: id | slide_id | user_id | headline | text 1 | 1 | 1000 | ... | .... 2 | 1 | 1001 | ... | .... So the database will contain many duplicates of that headline and text since it is the default. Is that a good idea? Or do I do something like this: define("DEFAULT_TEXT", "The text goes here and just used once in a file."); $text = ($stmt->num_rows < 1 ? DEFAULT_TEXT : $text); so I have a query that searches through my slide_data table to see if anything exists for tha