jeudi 29 janvier 2015

Design pattern to use for building a JSONObject for Network calls

Consider the following JSONObject which needs to be posted to a WebService to retrieve data.



{
"Search":"red",
"Index": 0,
"Size": 2,
"filter": {
"flags": {
"processed": true,
"hascode": true,
},
"lists": {
"category": ["1","2"],
"attributevalue": ["1","2"]
},
}
}


Which Design pattern would best be suitable for building this which has different objects in it. In the following, list and flag are objects with their own values and are inside the filter object. i was thinking of using the composite pattern but i don't know if it would be best to have those objects in the root object constructor and i have not seen one(Composite pattern) which uses getters and setters implemented in their design(which is what am currently doing for everything in the root object). not sure if any issues will arise using my approach so far? Any better design implementation or is composite the way to go? Thank you.


Design pattern to use for building a JSONObject for Network calls

Consider the following JSONObject which needs to be posted to a WebService to retrieve data.



{
"Search":"red",
"Index": 0,
"Size": 2,
"filter": {
"flags": {
"processed": true,
"hascode": true,
},
"lists": {
"category": ["1","2"],
"attributevalue": ["1","2"]
},
}
}


Which Design pattern would best be suitable for building this which has different objects in it. In the following, list and flag are objects with their own values and are inside the filter object. i was thinking of using the composite pattern but i don't know if it would be best to have those objects in the root object constructor and i have not seen one(Composite pattern) which uses getters and setters implemented in their design(which is what am currently doing for everything in the root object). not sure if any issues will arise using my approach so far? Any better design implementation or is composite the way to go? Thank you.


Singleton LoggedUser class on Infrastructure Layer?

I'am developing an multi-layered application that suport many application UI consumers, like WinForms and MVC.


First, i'am developing a UI Windows forms to consume that.


I have the falowing project structure:



Application.DataAccess - IUserRepository....
Application.Busines - IUserService, ICustomerService...
Application.Infrastructure - Logging, Exception handling... (Cross-cutting.)
Application.Domain - Entities, User, Customer...
Application.WindowsForms - UI


Most of my busines methods need User that has requesting like AddNewCustomer(Customer c, User requestingUser)...


I always have to pass Logged User through my User Interface application to Busines layer or should create a Singleton class on Cross-cutting layer and use that on all of my application?


Singleton LoggedUser class on Infrastructure Layer?

I'am developing an multi-layered application that suport many application UI consumers, like WinForms and MVC.


First, i'am developing a UI Windows forms to consume that.


I have the falowing project structure:



Application.DataAccess - IUserRepository....
Application.Busines - IUserService, ICustomerService...
Application.Infrastructure - Logging, Exception handling... (Cross-cutting.)
Application.Domain - Entities, User, Customer...
Application.WindowsForms - UI


Most of my busines methods need User that has requesting like AddNewCustomer(Customer c, User requestingUser)...


I always have to pass Logged User through my User Interface application to Busines layer or should create a Singleton class on Cross-cutting layer and use that on all of my application?


How to handle GET request in Content-provider centric design pattern for android

I am developing an android calendar app which will enable users to view, create, update and delete their events. To improve user experience and performance i have adopted a Content-provider centric design pattern which was recommended during Google IO 2010 conference on Android client application. I have successfully implemented the client rest service that create, update and delete events parsed from the content provider to a Restful web service written in PHP but i need some ideas on how to implement the get request in order to prevent data conflict and maintain accurate persistence on the client side. The restful web service returns a JSON payload of all the event based on a user's id, so i want to store these record in my content-provider with not conflict (is more like a sync). For instance, if a user re-installs his app, how do i ensure that the data already stored on the server is persistent which the application's content provider (which has a local SQLite database). A more basic explanation is populating the content-provider with non-duplicate events after the application is re-installed or an event is added directly to the server. Thanks in advances.


How to handle GET request in Content-provider centric design pattern for android

I am developing an android calendar app which will enable users to view, create, update and delete their events. To improve user experience and performance i have adopted a Content-provider centric design pattern which was recommended during Google IO 2010 conference on Android client application. I have successfully implemented the client rest service that create, update and delete events parsed from the content provider to a Restful web service written in PHP but i need some ideas on how to implement the get request in order to prevent data conflict and maintain accurate persistence on the client side. The restful web service returns a JSON payload of all the event based on a user's id, so i want to store these record in my content-provider with not conflict (is more like a sync). For instance, if a user re-installs his app, how do i ensure that the data already stored on the server is persistent which the application's content provider (which has a local SQLite database). A more basic explanation is populating the content-provider with non-duplicate events after the application is re-installed or an event is added directly to the server. Thanks in advances.


MVC design in iOS application similar to Whatsapp

I've been developing an application similar to Whatsapp (with its special features of course) and am now at the point where I think I should refactor all the existing code to make it conform with the MVC design pattern (because of too much glue code).


If I'll break my application to some simple stuff, we'll have:




  1. First Message:

    • ID

    • Any Unread Message

    • Source User

    • Target User



  2. Normal Message:

    • ID

    • First Message (weak reference)

    • Received State (Got to server/Got to client/Read by client)

    • Am i owner of message (am I source)

    • Date



  3. User:

    • ID

    • Phone Number

    • Profile Image Link





Note the "Any Unread Message" should be ON if there are any messages the user didn't read. just an optimization from the server.


I've never really worked with the MVC design pattern properly so I would like to make sure that my plans are correct or perhaps there are additional/other stuff I should do.


I was thinking about:




  • Model:

    • Create a Core-Data xcdatamodel file which will hold the above entities

    • Use the library mogenerator to generate entity files from the core-data model

    • Create Data-Models for each operation. for example: Register Data-Model which will handle all the registration api with the server; Message Data-Model which will handle sending a new message and retrieving new messages; etc. All of these will be singleton.



  • View:

    • all the views of whatsapp like outer UITableViewController (to display unique users) and inner UITableViewController (to display messages from a specific user).



  • Controller:

    • uses some of the above data models to fetch new data explicitly





I'm thinking to just give an API from the model to the controller which it can use it explicitly but that doesn't use the notifications or Key-Value-Observing designs.


I haven't found any online tutorial or document that explains what's the better thing to do.


Any suggestions?