3

I currently ran into a problem I can not really solve by myself:

I ve started to code a "small" framework (browsergame-framework), which follows the MVC pattern in some way.

Now I have my index, bootstrap, db adapter, dispatcher, wrapper, but I do not really know "how" to link them. I coded their methods etc. but I do not know how to design them to work like an engine.

And the next problem are my controllers, I do not know how to "link" them so that they easily can access the whole framework.... Yes, it is confusing, that is why I need your help, some generic scheme of "how a framework program flow" should like would be very nice.

Thank you.

3
  • yes i have same problem , i am confused about framework`s classes and their permissions . for example router classes explode the url and determines controller name and action name , so which part of framework should get thos information from router class and pass this information to controller class of framework . may be there should be 2 part of framework , first part is stand alone classes suc as (Router , database , view , controller) and second part of application should run function of these class and pass information between them ???? Commented Dec 6, 2009 at 16:01
  • 1
    Oguz: no part of the framework should get that information from router. another key principle of programming (related to DRY) is Tell, Don't Ask. Commented Dec 15, 2009 at 19:40
  • This php mvc tutorial could also help. Commented Dec 11, 2010 at 23:31

1 Answer 1

7

you're putting the cart before the horse. frameworks are not written, they're grown. see Evolving Frameworks from Ralph Johnson, one of the Gang of Four.

edit

I do not understand, what the author means with "application", does this mean raw-coded-project or does this mean project with basic functionality which will be taken to the later framework.

Either, depending on your expertise in programming and the problem domain. It's the goal (a useful framework) that's important, the process should simply support you in achieving it as best as possible. You may either start slow, develop three applications in the same problem domain without any code sharing among them, and just look at the code bases and see what they have in common, and possibly refactor these three finished applications to converge the code, and extract the common pieces. This won't give you any boost during the development of the second and third application, but neither will it hinder their development with concurrent refactoring of the previous ones.

Let's say you want a framework to ease writing browser-based, turn-based strategies.

Your first turn is to write such a game without thoughts of reusing the code outside this single game, but with attention to code reuse within it: refactor mercilessly, apply all the principles of programming: OCP, SRP, DRY, etc. Especially DRY. Code reuse (Don't Repeat Yourself) is a basic principle of programming, and the first step on the path to a framework. You will end up with a library of classes and/or functions that are used across the game.

Your second turn is to write, adhering to the principles mentioned above, another browser-based, turn-based strategy, using the code of the first game. You'll find that much of it is specific to that first game. Use the pieces that fit in the second one without modification, refactor those that are useful but don't quite fit so that they are useful and do fit in both games.

Repeat the procedure with the third game.

Three is the smallest number that gives you any hope of arriving at code that is truly reusable across the problem domain (think triangulation), not a guarrantee that it'll happen. OTOH, deriving a useful framework without the support of real-world applications is a sure way to end with a pile of useless crap.

Johnson:

Developing reusable frameworks cannot occur by simply setting down and thinking about the problem domain. No one has the insight to come up with the proper abstractions.

Read the "Three Examples" section carefully.

Sign up to request clarification or add additional context in comments.

3 Comments

I hope that this will help me ;) Even if it still does not tell me how to link the actual parts of the framework. And I do not understand, what the author means with "application", does this mean raw-coded-project or does this mean project with basic functionality which will be taken to the later framework.
@daemonfire300: i've expanded the answer to hopefully clear your doubts.
@j.s. thank you very much again. This will really help me, because I already have real-world models of some round-based games, I ll use to transfer some general logic into my code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.