Code, JavaEE, Technical

Conference Database – Part 2

Now, that we have a basic foundation to start building code upon the next thing to do is think about the design and user stories and / or use-cases for this project.

O+< User Story

As a conference sponsor, I want to capture contact information from attendees, in order to promote future events and provide special discounts to an exclusive list of customers.

At this point, I know what the main story is about. Before considering the database again, its time to focus on the object model. The model needs to represent at a high level what we are attempting to do and shadow the user story so that a specific implementation can happen. Let’s start by making a list of keywords from the user story.

Keywords

  • Conference Sponsor
  • Contact
  • Attendee
  • Event
  • Discount

The list is nice. But, what can this application do or what does the client expect it to do? A safe place to land is with the keyword Conference, since this is what we are building it makes sense to start there. At the moment the only thing I need the Conference to do is exist somehow and then I can add attendee information to it. The Conference will have its own set of properties/attributes.

The following code will begin building a representation of Conference and the required behavior to manage it. Create a Test Class named ConferenceTest under the package com.davidking under src/test. You should have an empty class as follows.


package com.davidking;

/**
 * ConferenceTest
 *
 * @author David King
 * Date: 6/15/13
 * Time: 5:23 PM
 */
public class ConferenceTest {
}

Add a method named testCreateConference to this class with the following code.


package com.davidking;

import org.junit.After;
import org.junit.Before;

/**
 * ConferenceTest
 *
 * @author David King
 * Date: 6/15/13
 * Time: 5:23 PM
 */
public class ConferenceTest {
 private ConferenceService conferenceService;

public void testCreateConference() {

}

@Before
 public void setUp() {
 conferenceService = new ConferenceService();
 }

@After
 public void tearDown() {
 conferenceService = null;
 }
}

You will notice that ConferenceService is in red, indicating that there is some issue (it doesn’t exist yet). Not too worry, we will create it by clicking ConferenceService and use the key combination ALT+ENTER and IntelliJ will display a context menu, choose Create Class ConferenceService and click OK. Now, you have a ConferenceService class.


package com.davidking;

/**
 * ConferenceService
 *
 * @author David King
 * Date: 6/15/13
 * Time: 5:32 PM
 */
public class ConferenceService {
}

Let’s add more code to the test case.

Update the testCreateConference method with the code below. Create the Conference class using the code given.


public void testCreateConference() {
 // A Conference requires a title and theme, let's create one
 Conference conference = new Conference("Tech Conference Expo 2013", "Expanding the mind");
 }

Conference.java


package com.davidking;

/**
 * Conference
 *
 * @author David King
 * Date: 6/15/13
 * Time: 5:38 PM
 */
public class Conference {
 private Integer id;
 private String title;
 private String theme;
 private Integer contactId;

public Conference(String title, String theme) {
 this.title = title;
 this.theme = theme;
 }

public Integer getId() {
 return id;
 }

public void setId(Integer id) {
 this.id = id;
 }

public String getTitle() {
 return title;
 }

public void setTitle(String title) {
 this.title = title;
 }

public String getTheme() {
 return theme;
 }

public void setTheme(String theme) {
 this.theme = theme;
 }

public Integer getContactId() {
 return contactId;
 }

public void setContactId(Integer contactId) {
 this.contactId = contactId;
 }

@Override
 public String toString() {
 return title;
 }
}

Now, the red lines should go away, we have a create test method, ConferenceService and Conference class so far so good.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s