Here's a translation of the same problem in Java.
Source example
public interface UserFactoryIF
{
User createNewUser();
}
Then Factory implementation
public class UserFactory implements UserFactoryIF
{
public User createNewUser()
{
return new User();
}
}
factory, . , , factory . , :
public interface User
{
public String getName();
public long getId();
public long getUUID();
}
factory :
public class UserFactory {
public static User createUserFrom(Person person) {
return new UserImpl( ... );
}
public static user createUserFrom(AmazonUser amazonUser) {
return new UserImpl( ... );
}
private static class UserImpl implements User {
}
}
, .