Jump to content

keeB

Staff Alumni
  • Posts

    1,075
  • Joined

  • Last visited

Everything posted by keeB

  1. I don't really understand your question. In any complex system a lot of patterns will show up.
  2. In MySQL, when you have a foreign key association you can set it to ON DELETE CASCADE. This is how to ensure everything is deleted in an association. But, in the end, if you're having problems with orphans it's because the app is not properly cleaning up after itself and the restrictions in the database are too light.
  3. Well, sure, but.. then you add complexity. If there's a good reason to add this complexity (I'm not sure there is, hence my original post,) no one is going to fault you for doing it. In the end, it's your decision to make. I'm just trying to get you to make the right one
  4. When working in a team environment, spaces. Save newlines as \n, not \r\n. Standards vary between teams, and can be anything from tabs to spaces to the combination of the two. The only thing that matters is consistency.
  5. Let's be fair. I also said I found it somewhat irritating. Of course, the engineer in me loves to explore and create something useful. Which I did. I wrote a Listbox implementation which you can see on the page. The irritating part is, that's about as far as I can go without reading related material in implementation. I can play around, sure, but really what I am left with is to actually read real world ncurses implementations, which is not trivial. The funny thing is, you and I believe in the same principles, they just seem to be lost a little in translation. I hate making things needlessly complex. I truly believe in creating simple, basic things. The process of leveraging these simple, basic things to create complexities which are easy to understand is almost artistic and (at least to me) beautiful.
  6. Isn't it my job as a vendor to advise my clients when buying my software? As I said, if you're smart you lose nothing. Drop the price in lieu of a support contract, or increase the price for a 1-off. Win win.
  7. I love this problem. Basically, how do you normalize a database where you have 2 different status for the same message? You don't want to enter the message in to the message table twice, as that's not optimal. Basically, the way that I would implement this is the following (pseudo-code): create table message ( message_id primary_key int not null, to text null , INDEX idx_message_to (to) FOREIGN KEY (to) REFERENCES user(user_id) --set up foreign key, index the to field. . . -- finish table creation ) create table message_mod ( id int primary_key not null, message_id int not null, -- another foreign key here on message(message_id) user_id int not null, -- another foreign key here on person/user status int not null ) So basically, what you have is 2 tables. MESSAGE contains all of the data, who sent it, when they sent it, the contents of the message, etc. MESSAGE_MOD contains the user modifications for the same entry. The satisfies the following case: - Bob sends Larry a message. - Bob checks his outbox and the status of his message is: Sent - Larry logs in to system and gets a notification of new Unread message. - Larry reads the message. - The status of the message has now been changed for Larry. - (A cool feature) Bob checks his outbox, and see's that Larry has read is message. The SQL to get changes for user 'some_user_1': SELECT m.subject, mod.status FROM message [m] LEFT JOIN message_mod [mod] ON m.message_id = mod.message_id WHERE m.user_id = 'some_user_1'
  8. Generally, what you're VB.Net coder was referring to was having a fragile base class. You can google this term for more clarity. If you're really interested, there's an article written by Allen Holub called 'Why Extends is Evil' [1] which should shed some light on it. Basically, he argues it's usually better to write to a concrete interface than to extend a base class. If inheriting and the base class changes, you have to worry about all classes which derive from it and how this affects them. I'm not as good at making the case, so you should probably just read the article. [1]: http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html
  9. What you want to implement is an Observer Pattern[1]. Here's a reference implementation in Python. It should port over quite easily for PHP. If you need any assistance or have any additional questions, I'll be happy to answer them. [1]: http://en.wikipedia.org/wiki/Observer_Pattern#Python
  10. I'm a purist. Hiding implementation is important for a number of things, but most of all encapsulation. Hiding the details of an implementation of an object is really important. What you're talking about now is a Model Object. Model objects are classes which contain a list of private members, and a series of Accessors / mutators to read/write data. The reason to not make the properties public is simple, you have a finer grain of control if you implement them as methods. Model objects are populated and passed around for a number of reasons: 1) For the presentation layer 2) Application Services to act on the data 3) Persistence layer for saving state. Model Objects are generally defined in the following way: <?php class Person { private $age ; private $height ; private $color ; public function __construct() {} //blank constructor. public function setAge($age) { $this->age = $age; } public function setHeight($height) { if (!is_int($height)) return; //do nothing if the height was not set properly, $this->height = $height; } . . . public function getHeight() { return $this->height; } public function getAge() { return $this->age; } } ?>
  11. Loot database is the way to go, imo. A'la Blizzard/World of Warcraft. Your decorators will do well. Let us know how it goes.
  12. You'll see when you look at the source. Basically there's a Weapon base class and each Weapon has special properties (damage, speed, knock back, splash radius, texture, etc) and you can get modifiers to globally increase damage/knockback (quad) speed (haste.)
  13. They weren't patterns per se, just a lot of math and each 'effect' having some multiplier for certain abilities.
  14. Normally RPG's user Modifiers, Multipliers, etc. As for code layout, I'll think of something and post. Quick Edit: You might want to look at the Quake 3 Source code or SDK. It has a lot of information on how their weapons are implemented. It's written in c++ but the syntax should be readable.
  15. Why do you need to add/remove photos? Just set the photo list once it's been open: <?php class User { private $photos = null; // this could also be PhotoList (or Gallery) if you want to have operations done on an entire set of photos. That's what I would recommend. private $userId = null; public function setPhotos($photos) { $this->photos = $photos; } public function getPhotos() { return $this->photos; } } ?>
  16. I didn't say a User could not have Photo's, I said that operations and data associated with photos should belong to photos.
  17. In that photos belong to a user? Sure. But they don't belong in the same object, nor does the handling of them.
  18. Well, I guess now you know why we kept telling you to take these methods out of the User class where they do not belong That would be terrible and illegible. What you're looking, honestly, is to create a few Model[1] Objects. <?php class UserPhotos { private $description = null; private $photo = null; private $address = null; public function setAddress($address) { $this->address = $address ; } public function addPhoto(Photo $photo) { $this->photos[] = $photo; //only on display should you care about limiting the amount of photos a user can have, or when you try to save. The responsibility doesn't need to be here. } public function setDescription(array $description) { $this->description = $description; } } [1]: http://en.wikipedia.org/wiki/Model_Object
  19. You don't. Name your classes more specifically and you won't have naming issues.
  20. Ooops, can't edit... [1]: http://en.wikipedia.org/wiki/Unified_Modeling_Language [2]: http://en.wikipedia.org/wiki/Class-Responsibility-Collaboration_card
  21. I guess I'll be the first to say it.. UML Diagrams [1] and CRC32 [2] cards. Since I work in a professional environment with all of the code that I write, the flow is something like this 1) My boss or I think of a missing tool that would be useful for testing our product. 2) Research best tools available to accomplish the job 3) If there aren't tools which accomplish what we need, I 3a) Write a high level proposal with cost analysis and project time line with deliverables at certain milestones. At this point I've thought on a high level how this would be accomplished but haven't gone in to any great level of detail. This is 3b) If proposal is accepted (which it usually is because I'm pretty damn good.. ) 3aa) Come up with design. UML and CRC32 cards are useful for figuring out issues right away. 3ab) Have a co-worker proof read design 3ac) Publish design proposal 3ad) If accepted, finally write the damn code! For anything non trivial, there's a lot of thought and pre-planning to do before you actually write code. The reason being, when you actually sit down to write it, you should have a very clear direction and goal.
  22. Corbin! Great advice. Use a database.
  23. Sound advice here. Just make a db.inc and include it in whichever page you need a database connection. Then, you can just call say $result = mysql_query("SELECT * FROM LOLO;", $db /* this is the resource created in db.inc */); Cheers
  24. Nothing to be sorry about Welcome and have a blast!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.