Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What would be a good MVC/OOP/GRASP/SOLID structure for a search/replace functionality. Methods: search/searchNext/replace/replaceAll.

I'm interested only in the PHP arhitecture and how a professional developer would implement this in it's OWN FRAMEWORK.

What names would you use for the classes? What subfolders would you used in your MODEL folder? How would you connect the MODELS/CONTROLLER?

This is just a arhitecture question to understand better the principles of good OOP in practice.

My current implementation is very simplistic using a service model:

 /controller/SearchReplaceController.php
 /models/services/SearchReplaceService.php

The problem with this is I know I'm breaking SRP in the service but I found this somehow acceptable. Also creating a service does not feel like the best solution for this.

share|improve this question
3  
Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask – gnat May 7 at 11:48
k, I added details about my current solution – danip May 7 at 11:52

2 Answers

my first suggestion would be - instead of thinking about the parts of the search methods - sketch out the people using the tool that you are building. give them specific names depending on their "Role". use those names in your design. Determine their needs -- what does the tool need to do for them? Determine their responsibilities -- what will they need to provide? From that determine what the application requirements are for that user.

Your class structure will then clearly represent the people using the application. you will automatically have the correct separation of concerns which will make it much easier to grow the application.

usually a search app would include some kind of admin role as well as end user role -- and since those two "Roles" are completely different, the class structure should reflect that. so like for a product search app - there might be a "Product Browser" role - the person who submits a search term and browses the results. and there could also be a "Product Admin" role who is taking care of the products that are getting searched on. by defining that separation of roles at the start, you can save a lot of time when building out your app.


  • first you determine the Roles - who are the actors on the application?
  • then write out the Use Cases - what are the actions that the actors make on the application? what are the results?
  • then there are Business Assets that are being acted upon, in this case a list of words.
  • and finally Implementation - how are you creating your application?

notice that implementation is last - the Roles and Use Cases drive the application - not the language, database type, etc. those are 'implementation details' that should not be part of the primary application design.

share|improve this answer
The Role that will use the search/replace functions is the "Editor Role". Based on this how would you create the arhitecture? – danip May 12 at 10:22
responded above – cartalot May 13 at 0:54

Like the above answer, I also think that you put the cart before the horse in this case. It sounds like you first thought about your architecture before having any requirements.

The usual way of developing software is to derive your architecture from the requirements you have, not only from the functional ones (in your case the Search/Replace functionality) but also - and mainly in most of the projects - from the non-functional ones (quality attributes) since those are the ones which cost you most of the money in the end if you missjudge them.

In your case the question is: Because you cannot perfectly implement every quality, what are the quality attributes you have to take care of most? As long as this question is not answered, nobody can give you a "blueprint" for a professional architecture that solves the search/replace functionality best.

Some of these quality attributes could be:

Performance: Do you have constraints regarding to the performance of the search/replace functionality?

Maintainablity: Should it be easy to change the searching/replacing algorithm? Should it be easy to change the UI which accesses your algorithms? (Possible hint to MVC)

MSDN has a nice summary on quality attributes: http://msdn.microsoft.com/en-us/library/ee658094.aspx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.