Modelling contact details for a person / customer
Date : March 29 2020, 07:55 AM
I hope this helps you . We know for sure what are the contact methods "email, "phone" and "address", so having identified those what we have to do first is to model those concepts taking into account what they really are. Let's take "email" as example and see what it really is in order to model it properly. It is a value object (an immutable object) that once created it will never change just as an integer number is an immutable object as well. The difference is that for modelling an integer number we can use the int type provided by any programming language, but the question is what class do we use for modelling en Email? Most of people would use a String instance to model an Email, but is this OK? In order to answer it let's see what is the protocol (the set of messages) a String object knows to response: "charAt(anIndex), replace(aString, anotherString), etc... ". Imagine that if we model an email by using a String class we could ask the email "replace(aString, anotherString)". That sounds weird, that message should not be part of the behavior an email should expose to other objects. Also so so important we said an email is immutable to it cannot expose behavior that at the end change it state. So it makes visible that we need to create a whole new abstraction to model an email and what is it? The Email class finally comes in!!! I know you suggested it but I just wanted to let you see why we need an Email class created. First of all this is DDD (object oriented) so FORGET avoid setters and getters. In the email class you created you expose a setter method meaning that you can change the email and it contradicts with the nature of what an email is (immutable). An email is immutable from the momento it is created: Email.fromString("monicalewinsky@gmail.com");
new Email("monicalewinsky@gmail.com");
Email(String anEmailStringRepresentation) {
assertIsValid(anEmailStringRepresentation);
}
class Email {
String value;
Email(aString) {
value = aString;
}
public String getLocalPart()
public String getDomainPart()
public String asString()
public boolean equals(anObject)
public static Email fromString(aString)
}
ContactMethod.for(Email.fromString("monica@gmail.com"));
ContactMethod.for(PhoneNumber("34234234234"));
class ContactMethod {
static EMAIL = 1;
static PHONE_TYPE = 2;
static ADDRESS_TYPE = 3;
String type;
String value;
ContactMethod(int aType, String aValue) {
type = aType;
value = aValue;
}
String getType()
String getValue()
public static ContactMethod at(Email anEmail) {
return new ContactMethod(EMAIL, anEmail.asString());
}
public static ContactMethod at(PhoneNumber aPhoneNumber) {
return new ContactMethod(PHONE_TYPE, aPhoneNumber.asString());
}
public static ContactMethod at(Address anAddress) {
return new ContactMethod(ADDRESS_TYPE, anAddress.asString());
}
}
class Person {
List<ContactMethod> contactMethods;
contactedAt(Email anEmail) {
contactMethods.add(ContactMethod.at(anEmail));
}
contactedAt(PhoneNumber aPhoneNumber) {
contactMethods.add(ContactMethod.at(aPhoneNumber));
}
contactedAt(Address anAddress) {
contactMethods.add(ContactMethod.at(anAddress));
}
}
|
How add a customer to an order when getting the customer details from a form
Tag : mysql , By : Milander
Date : March 29 2020, 07:55 AM
With these it helps Insert the customer details first. Then get the ID of the newly inserted customer and use it while inserting the order details! You could use the LAST_INSERT_ID() after you insert the user details to the db to get the ID of the customer.
|
First person's account details displayed for second person when two people are logged in
Tag : java , By : bashmish
Date : March 29 2020, 07:55 AM
help you fix your problem I have an issue that when more than one person is signed onto the application it is picking up the details of the first person's account details for the second person. public ViewData getViewData() {
return viewData;
}
public void setViewData(viewDataFromClient) {
getThreadLocalRequest().getSession(true).setAttribute("key-goes-here", new ViewData());
//...
public ViewData getViewData() {
return (ViewData) getThreadLocalRequest().getSession().getAttribute("key-goes-here");
}
//Store and retrieve data used by Views within the application
//This allows us to securely pass parameters between Views.
private ViewData viewData = null;
public ViewData setViewData(String accountId, String accountLevel,
String ymId, String awId, String adAwardGroup, String adScoutGroup,
String caId, Integer numberOfGroupsStarted, String groupSection) {
getThreadLocalRequest().getSession(true).setAttribute
(accountId, new ViewData());
viewData.setaccountId(accountId);
viewData.setaccountLevel(accountLevel);
viewData.setymId(ymId);
viewData.setawId(awId);
viewData.setadAwardGroup(adAwardGroup);
viewData.setadScoutGroup(adScoutGroup);
viewData.setcaId(caId);
viewData.setnoGroupsStarted(numberOfGroupsStarted);
viewData.setsection(groupSection);
return viewData;
}
public ViewData setViewData(String accountId, String accountLevel,
String ymId, String awId, String adAwardGroup, String adScoutGroup,
String caId, Integer numberOfGroupsStarted, String groupSection) {
//create a view data object with the specific details
ViewData viewData = new ViewData();
viewData.setaccountId(accountId);
viewData.setaccountLevel(accountLevel);
viewData.setymId(ymId);
viewData.setawId(awId);
viewData.setadAwardGroup(adAwardGroup);
viewData.setadScoutGroup(adScoutGroup);
viewData.setcaId(caId);
viewData.setnoGroupsStarted(numberOfGroupsStarted);
viewData.setsection(groupSection);
//store the data in the session so we remember it when the user comes back
getThreadLocalRequest().getSession(true).setAttribute(accountId, viewData);
//return the viewdata to the user
return viewData;
}
|
Finding out only certain Master items from Details table in a Master-Details table relationship
Date : March 29 2020, 07:55 AM
like below fixes the issue I've been trying to get this going for hours and haven't figured this out yet. , You need simple GROUP BY with HAVING clause : select master_id
from details
where tag in ('WINDOWS', 'MAC')
group by master_id
having count(*) = 2;
|
How to sync master SQL Server database with multiple customer data to individual customer db's
Tag : chash , By : TheDave1022
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I would just optimize your custom solution. It doesn't sound like it's a complicated-enough scenario to benefit from a full Sync/Repl framework. Plus you should be planning to move from CE to SqlLite, or otherwise move off of CE.
|