I have a specific design Query. We have a FrontendWebsite(Site1) which is connected to backend DB via a WCF Service (Site1Service). We have to integrate our FrontendWebsite(Site1) with some 3rd Party API's, let's say Google API. So we have 2 options to call this 3rd API as: 1. Call directly from FrontendWebsite(Site1). 2. Call from WCF Service (Site1Service). The WCF Service (Site1Service) already has reference to Google API. So what are the best practices around this use case? How should we call 3rd party API? Should we decouple FrontendWebsite(Site1) from 3rd party API like Google API?
lundi 25 janvier 2016
Suitable J2EE Design Pattern
I have been mostly working on core java and not need to work on the J2EE part of the same in creating a web application.
I have a query with respect to design of the code.
If I am using J2EE as it is, without using any MVC framework, then all my request comes to my server in my servlet from my JSP.
Now in the Servlet, I want to perform a fixed number of operations
Eg: verifying the order, checking customer details, etc.
If these fixed operations are fine, then execute the another service.
In this case, should I use a single servlet and from there call different services OPerations based on if-else logic internally or Should I use different servlets and pass them the request&response object based on wheather the operation is success or failed.
(I want to follow the right design and keep my code clean and loosely coupled)
So in breif, it is like Servlet calling Operation A,B. If A=true, B= true, call Operation C
Servlet calling Operation A,B. If A=true, B= false, call Operation D
Servlet calling Operation A,B. If A=false, B= true, call Operation E
Based on different outcomes, I will render different pages. So in this case, will it be a good Idea to invoke a separate servlet for each operation ??
Kindly advice me with a score to my solution and further improvements to it
Please let me know in case my question is not appearing clear or need any more information.
Thanks
Cheers.:)
dimanche 24 janvier 2016
IOS : Best practices for Fields Validation on User Interface
In my app I want to validate user inputs in the field. For Example
If textfields is empty. Or email is in correct formate
I don't want to add validation logic in ViewController, Neither I want to pass UIView to a Validator Class
I have multiple screens like this.
Any suggestion for best ways validating Screens.
Is IntentService an implementation of Command Processor Pattern?
According to Wikipedia:
"In object-oriented programming, the command pattern is a behavioral design pattern in which an object is used to encapsulate all information needed to perform an action or trigger an event at a later time. This information includes the method name, the object that owns the method and values for the method parameters."
And according to professor Schmidt's text, a command has:
- Time-independent execution of application logic. The encapsulation of application logic allows to queue it and execute it at a different point in time.
- Context-independent execution of the application logic. The separation between application logic and context allows to execute the application in separate contexts, such as in a different thread or using a different state.
- Exchangeability of application logic. The separation between application logic and context allows to easier exchange the application logic.
If you encapsulate all information into an Intent, the onHandleIntent works as an abstract method to the command executor, just like described at command processor pattern text.
So the questions are:
- Is IntentService the framework implementation for command executor pattern?
- In affirmative case, why some Android MVP implementations explicitly implements its own executor instead of using the one provided by the framework?
How to better design and organize the code in my tab based app?
I have a tab-based android application. There is a main activity that controls 5 fragments, each fragment is a tab in the application.
All tabs in my application are very similar to one another and share a number of properties and methods.
There are a couple issues I am having though. I thought about making a parent fragment class that each fragment could inherit from, since all tabs have similar properties such as a tabName, tabNumber, numOfCheckBoxes, things like that. However, whenever I switch tabs, my FragmentPagerAdapter returns a new instance of the fragment corresponding to the tab I clicked. This means that I have to make all of my tab variables static so that they persist through switching tabs. My main activity needs to be able to view information about a specific tab even when I have left that tab and moved on to another.
Now the problem with this is that if I make a static variable in the parent class, then that property is shared amongst all tabs, which I can't have.
Is this bad design? I am very confused on how to structure my tab based app so that I am not rewriting a bunch of code, but also knowing information about each tab even while that tab may not be active.
Design pattern for business operations involving several objects
Let's say I want to perform an operation that involves updating data in several objects.
Here's an example:
void SomeOperation()
{
order.SetStatus(OrderStatus.ReadyForShipping);
order.Save();
email = emailFactory.CreateOrderIsReadyEmail(order);
mailService.QueueEmail(email);
mailService.Save();
shippingHandler = shippingHandlerSelectionStrategy.select(order.Location);
shippingHandler.addItem(order);
shippingHandler.Save();
orderStatistics.AddReadyForShippingOrder(DateTime.Today);
orderStatistics.Save();
}
Where exactly should this code go?
Should it be it's own class? Something like this?
class ReadyForShippingOperation : Operation
{
override void Execute()
{
// ...
}
}
But what if this operation has very specific business rules for when it can be executed, the sort of rules that would require intimate knowledge of those objects?
For example, say we can only execute this operation when an order is a certain state. But this state is not some value on the order, it's a very specific set of requirements that's only ever relevant to this operation.
Do I really want to add something like this to my order object?
class Order
{
bool IsReadyForThatShippingOperation();
}
This method only concerns the order insofar as it's implementation is highly coupled with the order's data. But conceptually it's not really part of the order. It's relevant only for our one operation.
Another option would be to make the details of the order public. This also doesn't feel right. For example, our operation class might look like:
class ReadyForShippingOperation : Operation
{
override void Execute()
{
if (!OrderIsReady(order)) {
// Handle error
}
// ...
}
bool OrderIsReady(order)
{
if (order.CreatedDate > someValue) return false;
if (order.LastUpdatedDate > someValue) return false;
if (!order.IsValid) return false;
if (!order.chachingState == InProgress) return false;
return true;
}
}
What happens in this case is I find myself forced to expand the Order API, for the single purpose of giving the OrderIsReady() method permission to grasp its dirty hands around it.
Perhaps this example is too specific. In general what I really want to know is how to best organize business operations that require intimate data from many objects but don't seem to belong to any one object.
Factory Design Pattern Generic return Type
I want to implement factory design pattern with a generic return type. I have created this example but I can't get it to work. How can my factory return a type of generic and how do I use it in main class. Here is my code:
namespace ConsoleApplication1
{
using System;
using System.Collections.Generic;
class MainApp
{
static void Main()
{
Factory fac = new Factory();
IPeople<T> pep = fac.GetPeople(PeopleType.RURAL);
Console.WriteLine(pep.GetList());
}
}
public interface IPeople<T>
{
List<T> GetList();
}
public class Villagers : IPeople<DomainReturn1>
{
public List<DomainReturn1> GetList()
{
return new List<DomainReturn1>();
}
}
public class CityPeople : IPeople<DomainReturn2>
{
public List<DomainReturn2> GetList()
{
return new List<DomainReturn2>();
}
}
public enum PeopleType
{
RURAL,
URBAN
}
/// <summary>
/// Implementation of Factory - Used to create objects
/// </summary>
public class Factory
{
public IPeople<T> GetPeople(PeopleType type)
{
switch (type)
{
case PeopleType.RURAL:
return (IPeople<DomainReturn1>)new Villagers();
case PeopleType.URBAN:
return (IPeople<DomainReturn2>)new CityPeople();
default:
throw new Exception();
}
}
}
public class DomainReturn1
{
public int Prop1 { get; set; }
}
public class DomainReturn2
{
public int Prop2 { get; set; }
}
}