Busy Java Developer's Guide to NakedObjects

ted@tedneward.com | Blog: http://blogs.tedneward.com | Twitter: tedneward | Github: tedneward | LinkedIn: tedneward

History

Where it all began

Smalltalk: Overview

The original O-O language

Overview

Smalltalk is...

... programming language

... and environment

Overview

Current Smalltalk implementations

Smalltalk

A History

History

Smalltalk's history is long and distinguished

History

Smalltalk influenced...

History

Smalltalk influenced...

History

Smalltalk influenced...

History

Smalltalk influenced...

History

Began on a bet

History

Objects introduced in Smalltalk-80

History

Smalltalk incorporated IDE and runtime into one tool

Model/View/Controller

Separating display from logic

Model/View/Controller

MVC is a design pattern that appears frequently in GUI systems

Model/View/Controller

Origins lie in Smalltalk

Model/View/Controller

MVC showed up in a number of GUI systems

Model/View/Controller

In the original MVC...

Model/View/Controller

Parting thoughts

Model/View/Controller

MVC has spawned a lot of similar ideas/patterns

Model/View/Controller

Resources

Naked Objects

Wait.... what?

Naked Objects: Overview

In the old days...

Naked Objects: Overview

What's wrong with the way we do applications today?

Naked Objects: Overview

New idea: Let the UI center around the objects

Naked Objects: Overview

Benefits:

Naked Objects: Basics

Understand the principles of Naked Objects

Basics

Naked Objects frameworks core concepts

Basics

Domain objects

Basics

Properties

Basics

Actions

Basics

Value types

Basics

Services

Basics

Factories/respositories

Basics

External services

Basics

Contributed actions

Getting Started

Naked Objects in Java: Apache Isis

Getting Started

Apache Isis

Getting Started

Bootstrap the Maven archetype

Getting Started

Build an empty Isis application

mvn archetype:generate  \
    -D archetypeGroupId=org.apache.isis.archetype \
    -D archetypeArtifactId=simpleapp-archetype \
    -D archetypeVersion=1.15.0 \
    -D groupId=com.mycompany \
    -D artifactId=myapp \
    -D version=1.0-SNAPSHOT \
    -D archetypeRepository=http://repository-estatio.forge.cloudbees.com/snapshot/ \
    -B

Getting Started

Build and run the app

$ cd myapp
$ mvn clean install
$ mvn -pl webapp jetty:run

Browse to http://localhost:8080 (login w/ "sven"/"pass")

Domain Objects

Domain/subject entities in Apache Isis

Isis Domain Objects

Start with "simple" O-O domain class

Isis Domain Objects

Isis uses Java annotations to carry metadata

Isis Domain Objects

@DomainObject

Isis Domain Objects

Domain Objects

@DomainObjectLayout()
@DomainObject(auditing = Auditing.ENABLED)
public class Convention
    implements Comparable<Convention> 
{

Isis Domain Objects

Properties

Isis Domain Objects

@Property annotation customizes property details

Isis Domain Objects

Domain Objects

    @javax.jdo.annotations.Column(allowsNull = "false", length = 40)
    @lombok.NonNull
    @Property(editing = Editing.DISABLED)
    @Title(prepend = "Convention: ")
    @MemberOrder(sequence="1")
    private String name;
    
    public String getName() { return this.name; }
    public void setName(String val) { this.name = val; }

Isis Domain Objects

Domain Objects

    @javax.jdo.annotations.Persistent
    @javax.jdo.annotations.Column(allowsNull = "true")
    @Property(editing = Editing.ENABLED)
    @MemberOrder(name="Dates", sequence="1")
    private LocalDate start;
    public LocalDate getStart() { return this.start; }
    public void setStart(LocalDate val) 
    {
        this.start = val;
        // calculate some reasonable values for the other dates
    }
    public String validateStart(LocalDate proposed) {
        // validate the start date is in the future (from now)
        return null;
    }

Isis Domain Objects

Properties can be validated

Isis Domain Objects

Actions

Isis Domain Objects

@Action annotation used to customize actions

Isis Domain Objects

Domain Objects

    @Action(semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE)
    public void delete() {
        final String title = titleService.titleOf(this);
        messageService.informUser(String.format("'%s' deleted", title));
        repositoryService.removeAndFlush(this);
    }

Isis Domain Objects

Dependent services are injected

Isis Domain Objects

Domain Objects

    @javax.inject.Inject
    @lombok.Getter(AccessLevel.NONE) @lombok.Setter(AccessLevel.NONE)
    EventRepository eventRepo;
    
    @javax.inject.Inject
    @lombok.Getter(AccessLevel.NONE) @lombok.Setter(AccessLevel.NONE)
    RepositoryService repositoryService;
    
    @javax.inject.Inject
    @lombok.Getter(AccessLevel.NONE) @lombok.Setter(AccessLevel.NONE)
    MessageService messageService;
    
    @javax.inject.Inject
    @lombok.Getter(AccessLevel.NONE) @lombok.Setter(AccessLevel.NONE)
    TitleService titleService;

Isis Domain Objects

Presentation is derived from class

Isis Domain Objects

Presentation "hints" can come elsewhere

Isis Domain Objects

Presentation "hints" can come elsewhere

Isis Domain Objects

Object lifecycle

Isis Domain Objects

Persistence is handled by JDO

Isis Domain Objects

JDO class annotations

Isis Domain Objects

JDO class annotations

Isis Domain Objects

Domain Objects

@javax.jdo.annotations.PersistenceCapable(
    identityType = IdentityType.DATASTORE, schema = "dragonflight" )
@javax.jdo.annotations.DatastoreIdentity(
    strategy = IdGeneratorStrategy.IDENTITY, column = "id")
@javax.jdo.annotations.Version(
    strategy= VersionStrategy.DATE_TIME, column ="version")
@javax.jdo.annotations.Queries({
        @javax.jdo.annotations.Query(
                name = "findByName",
                value = "SELECT "
                        + "FROM domainapp.dom.impl.Convention "
                        + "WHERE name.indexOf(:name) >= 0 ")
})
@javax.jdo.annotations.Unique(name="Convention_name_UNQ", members = {"name"})
// Should have a query that finds the upcoming one (by date)

Isis Domain Objects

JDO field annotations

Isis Domain Objects

Object lifecycle methods

Isis Domain Objects

Object lifecycle methods

Services

Naked services in Apache Isis

Services

Services are "just" domain objects

Services

Isis-provided services

Services

Isis-provided services

Services

Despite that, you will want to write your own services

Services

Services are "just" domain objects

Services

Presentation

Naked Objects: Resources

Where to go for more information/ideas/etc

Resources

Reading

Credentials

Who is this guy?