model view controller - How to properly implement the Strategy pattern in a web MVC framework? -
In my Django app, I have a model with a field called "Type" (Fu calls). I want to use Foo.type for a specific example of Foo (possibly "number", "date", "one line of text", "multiple lines of text", and some other). .
There are two things that like the "Type" field to affect me; The way in which a value is converted from its usual type of text (for example, in "date", it can be str (the_date.isoformat ()) , and by the way The value is converted to text Specified type (in "Date", it can be datetime.date.fromtimestamp (the_text) ).
For me, this strategy pattern (I may be completely wrong, and if I am, do not hesitate to improve me). My question is that What is the correct way of code in the MVC framework?
In the client-side app, I " Override those methods in classes (such as number type and date type), and dynamically set the "type" field to the appropriate type subclass at the runtime of a new instant.
The outline in the web is not easy enough for me, just like It is most understandable, it defines Fu as a small integer area and defines a limited option (0 = "number", 1 = "date", 2 = "single row of text") is. Etc.) in the code. Then, when a foo object is instant, use the factory method to see the value of the "type" field of the example and plug in the correct type subclass (described in the paragraph above). Fu will also have serialized () and precise () methods, which will be directly representative in the sub-category of the plug-in type.
How does this design sound? I have never played this issue before, so I really want to know what other people have, and how they have solved it.
You can view through Warrant stuff which provides the Django. This will give you exactly the sub-classes whatever the models / scholars, different tables etc.
FU # Base Datufu (FU) Other FU (FU) etc ...
Comments
Post a Comment