Created
October 21, 2019 00:42
-
-
Save minhd/abb4431dd39ea4bbe55f97225cfe829a to your computer and use it in GitHub Desktop.
Enterprise Java i++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
IIncrementorAbstractFactoryThatCreatesConcreteIncrementorFactoriesForIncrementing factoryFactory = new IncrementorAbstractFactory(); | |
IIncrementorFactoryThatCreatesIIncrementorThatIsUsedForIncrementingDifferentTypesOfObjects incrementorFactory = new IncrementorFactoryThatCreatesIncrementorsUsedForIncrementingThings(); | |
IIncrementorThatIsUsedForIncrementingDifferentTypesOfObjects incrementor = incrementorFactory.CreateIncrementor(IncrementorTypeEnumThatRepresentsAnIncrementorTypeOfSomeSort.Integer); | |
IntegerIncrementorThatCanTakeAnIntegerAndIncrementItByOne intIncrementor = incrementor as IntegerIncrementorThatCanTakeAnIntegerAndIncrementItByOne; | |
object incrementedIntObj = intIncrementor.IncrementAnObjectTypeAndReturnAnObjectThatIsAnIncrementOfTheObjectTypePassedIn(5); | |
int incrementedInt = Convert.ToInt32(incrementedIntObj); | |
} | |
public enum IncrementorTypeEnumThatRepresentsAnIncrementorTypeOfSomeSort | |
{ | |
Integer, | |
DateTime | |
//define other incrementors types here | |
} | |
public interface IIncrementorAbstractFactoryThatCreatesConcreteIncrementorFactoriesForIncrementing | |
{ | |
IIncrementorFactoryThatCreatesIIncrementorThatIsUsedForIncrementingDifferentTypesOfObjects CreateIncrementorFactory(); | |
} | |
public interface IIncrementorFactoryThatCreatesIIncrementorThatIsUsedForIncrementingDifferentTypesOfObjects | |
{ | |
IIncrementorThatIsUsedForIncrementingDifferentTypesOfObjects CreateIncrementor(IncrementorTypeEnumThatRepresentsAnIncrementorTypeOfSomeSort incrementorType); | |
} | |
public interface IIncrementorThatIsUsedForIncrementingDifferentTypesOfObjects | |
{ | |
object IncrementAnObjectTypeAndReturnAnObjectThatIsAnIncrementOfTheObjectTypePassedIn(object tVar); | |
} | |
public class IntegerIncrementorThatCanTakeAnIntegerAndIncrementItByOne : IIncrementorThatIsUsedForIncrementingDifferentTypesOfObjects | |
{ | |
public object IncrementAnObjectTypeAndReturnAnObjectThatIsAnIncrementOfTheObjectTypePassedIn(object tVar) | |
{ | |
int intToIncrement = Convert.ToInt32(tVar); | |
return intToIncrement = intToIncrement + 1; | |
} | |
} | |
public class IncrementorFactoryThatCreatesIncrementorsUsedForIncrementingThings : IIncrementorFactoryThatCreatesIIncrementorThatIsUsedForIncrementingDifferentTypesOfObjects | |
{ | |
public IIncrementorThatIsUsedForIncrementingDifferentTypesOfObjects CreateIncrementor(IncrementorTypeEnumThatRepresentsAnIncrementorTypeOfSomeSort incrementorType) | |
{ | |
switch (incrementorType) | |
{ | |
case IncrementorTypeEnumThatRepresentsAnIncrementorTypeOfSomeSort.Integer: | |
return new IntegerIncrementorThatCanTakeAnIntegerAndIncrementItByOne(); | |
case IncrementorTypeEnumThatRepresentsAnIncrementorTypeOfSomeSort.DateTime: | |
// TODO: create DateTime incrementer and implement here. | |
return null; | |
default: | |
return null; | |
} | |
} | |
} | |
public class IncrementorAbstractFactory : IIncrementorAbstractFactoryThatCreatesConcreteIncrementorFactoriesForIncrementing | |
{ | |
IIncrementorFactoryThatCreatesIIncrementorThatIsUsedForIncrementingDifferentTypesOfObjects IIncrementorAbstractFactoryThatCreatesConcreteIncrementorFactoriesForIncrementing.CreateIncrementorFactory() | |
{ | |
return new IncrementorFactoryThatCreatesIncrementorsUsedForIncrementingThings(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment