Page 1 of 1

PHP+OOP simple usersystem, how?

Posted: Sun Jul 10, 2005 12:25 pm
by kawsper
Hello.
I am an middle experienced php-programmer, and in my journey to new languages i have tried to learn Java and C++ and therefore i have gained a little experience in OOP.
Before simple Java and C++ OOP gave no meaning to me at all in a website, but now i see the advantages and want to use it, but i have a lot of troubles designing and thinking in the new way of OOP.

I want to create a simple user system with a few features to learn to think and learn to work with PHPs "limited" OOP features, but i thought that i could get some help on how to design my classes and functions (Not code it, but how to design it in theory).

The features:
- Login/Logout :roll: .
- Show profile info (Age, Sex, Name, Admin-level).
- Save/Edit profile info ( - | | - ).
- One admin feature = Delete user.

Thanks in advance.

Posted: Sun Jul 10, 2005 4:20 pm
by McGruff
Would you like to explore this with TDD (test-driven-design)?

The idea is that you first write a test for a new class then you write some code to satisfy the test. Repeat until done.

Objects often interact with other objects. In TDD, you might "discover" one of these while you're testing/writing a class. If you're trying to keep a clear separation of responsibilities, you might find something that needs doing that doesn't fit well in the current class: this should be encapsulated by some other object (or objects).

Since it doesn't yet exist, a mock object is created for the test. This basically just defines an interface then, with a framework like SimpleTest, you can set expectations for the number of times methods will be called and what arguments will be passed to them. You can also hard-code return values for mock object methods so that, in the test, they behave in the same way you want the real object to perform.

The point of this is to allow you to explore a design from the top down. Just start coding and see what happens. The mocks define interfaces for neighbouring objects. When you're done testing the first class, you write implementations of the mocks. In turn these might need to use other objects which are mocked for the test, and so on and so on. The design ripples out from the first class.

Posted: Mon Jul 11, 2005 10:10 am
by pickle
The show profile info and safe/edit profile info are obviously going to be able to be put in your user object. Depending on how you feel about it, you may be able to put the delete/add (the second admin feature you're likely going to want :) ) in that object as well. I don't know if I'd put the login/logout functionality in the object though - doesn't seem to fit in the object.

What in particular did you want advice/help on? You seem to be going in the right direction so far.