44
1 Hierarchy Hierarchy The Next Step in the Java The Next Step in the Java Language Language Created by Created by

Why Java Needs Hierarchical Data

Embed Size (px)

Citation preview

Page 1: Why Java Needs Hierarchical Data

11

HierarchyHierarchy

The Next Step in the Java LanguageThe Next Step in the Java Language

Created byCreated by

Page 2: Why Java Needs Hierarchical Data

22

IntroductionIntroduction

Peter JohPeter Joh – Head of Development of – Head of Development of Hierarchy at our company, Unconventional Hierarchy at our company, Unconventional ThinkingThinking

15 years of development experience15 years of development experience

Several years working on research about Several years working on research about Software-ArchitectureSoftware-Architecture

5 years running Unconventional Thinking5 years running Unconventional Thinking

4 years working on Hierarchy4 years working on Hierarchy

Page 3: Why Java Needs Hierarchical Data

33

Today’s talkToday’s talk

Part 1 – Introduce You to HierarchyPart 1 – Introduce You to Hierarchy Part 2 – Benefits of Using Hierarchy Part 2 – Benefits of Using Hierarchy

in your Systemsin your Systems Conclusion – The Future of Conclusion – The Future of

HierarchyHierarchy Extra MaterialExtra Material – N-Dimensional – N-Dimensional

Architecture - Architecture - OPTIONALOPTIONAL Discussion – Q & A and Discuss Discussion – Q & A and Discuss

Taking On your Own Software IdeasTaking On your Own Software Ideas

Page 4: Why Java Needs Hierarchical Data

44

Part 1 – Introduction to Part 1 – Introduction to HierarchyHierarchy

Page 5: Why Java Needs Hierarchical Data

55

What is Hierarchy?What is Hierarchy?

public class MyClass {

public void myMethod() {

System.out.println(“Some data from a ”+

“matrix: ” + MyMatrix->CONTENT:>SomeData);

}

}

Page 6: Why Java Needs Hierarchical Data

66

Hierarchy is a Meta-Hierarchy is a Meta-CompilerCompiler

Pure Java file

public class MyClass { public void myMethod() {

String myVar = MyMatrix:>SomeData; }

}

Embedded Java file

Hierarchy

public class MyClass { public void myMethod() {

String myVar = MyMatrix.get_FieldSet() .getField_SomeData(); }

}

Page 7: Why Java Needs Hierarchical Data

77

What does Hierarchy What does Hierarchy Add to Java?Add to Java? Hierarchical DataHierarchical Data

XML File Type Hierarchy XML File Type Hierarchy EquivalentEquivalent

.xml -> .matrix.xml -> .matrix

.xsd -> .schema.xsd -> .schema

.xsl -> .mjava*.xsl -> .mjava*

*.mjava is not quite the same as .xsl *.mjava is not quite the same as .xsl

Page 8: Why Java Needs Hierarchical Data

8

Willie’s Petstore

news

Adopt-a-Pet Day is this Sunday! March 17th

Your chance to adopt a lonely doggie is right around the corner.

20% off Fanciful Dog Spread March 12th

For one day only, come and pick up your tub of Fanciful Dog Spread!

Page 9: Why Java Needs Hierarchical Data

9

WilliesPetstore.matrix package com.williespetstore;

import java.text.DateFormat;

MATRIX WilliesPetstore.Content USES (News.Schema) {  NEWS: {"HomePage News Blurbs"} {

    NEWS.STORY +`Adopt a Pet`: {     DateFormat.getDateInstance().parse("March 17,2010"),    "Adopt a Pet",    "Your chance to adopt a lonely doggie is right " +    "around the corner." };

   NEWS.STORY +`Fanciful Dog Food`: {    DateFormat.getDateInstance().parse("March 10,2010"),    "20% off Fanciful Dog Spread",     "For one day only, come and pick up your tub of " +    "Fanciful Dog Spread!"    }; }

}} AVAILABLE ON HANDOUT

Page 10: Why Java Needs Hierarchical Data

10

WilliesPetstore.matrix package com.williespetstore;

import java.text.DateFormat;

MATRIX WilliesPetstore.Content USES (News.Schema) {  NEWS: {"HomePage News Blurbs"} {

    NEWS.STORY +`Adopt a Pet`: {     DateFormat.getDateInstance().parse("March 17,2010"),    "Adopt a Pet",    "Your chance to adopt a lonely doggie is right " +    "around the corner." };

   NEWS.STORY +`Fanciful Dog Food`: {    DateFormat.getDateInstance().parse("March 10,2010"),    "20% off Fanciful Dog Spread",     "For one day only, come and pick up your tub of " +    "Fanciful Dog Spread!"    }; }

}}

Descriptors

Field Sets

Page 11: Why Java Needs Hierarchical Data

11

News_Schema.schemaNews_Schema.schemapackage com.williespetstore;

SCHEMA News.Schema {

DESCRIPTOR +:%NEWS { FIELD.NAMES: { +:%NewsSectionName }; FIELD.TYPES: { :String };

DESCRIPTOR +:%NEWS.STORY {

FIELD.NAMES: { +:%StoryDate, +:%Title, +:%StoryContent }; FIELD.DESC: { "The date of the story", "The title of the story", "The content of the story" }; FIELD.TYPES: { +:"java.util.Date", :String,

:String }; } }} AVAILABLE ON HANDOUT

Page 12: Why Java Needs Hierarchical Data

12

News_Schema.schemaNews_Schema.schemapackage com.williespetstore;

SCHEMA News.Schema {

DESCRIPTOR +:%NEWS { FIELD.NAMES: { +:%NewsSectionName }; FIELD.TYPES: { :String };

DESCRIPTOR +:%NEWS.STORY {

FIELD.NAMES: { +:%StoryDate, +:%Title, +:%StoryContent }; FIELD.DESC: { "The date of the story", "The title of the story", "The content of the story" }; FIELD.TYPES: { +:"java.util.Date", :String,

:String }; } }

} * Notice Field definitions line up vertically

Field Set Definitions

Descriptor Definitions

Page 13: Why Java Needs Hierarchical Data

How do Schemas How do Schemas Work?Work?

AVAILABLE ON HANDOUT

Page 14: Why Java Needs Hierarchical Data

14

WilliesPetStoreConsoleApp.mjavapackage com.williespetstore;

import MATRIX com.williespetstore::WilliesPetstore.Content;

public class WilliesPetStoreConsoleApp {

public static void main(String[] args) {

System.out.println("Willie's Pets and Things\n"); System.out.println("news:");

for(DESCRIPTOR<WilliesPetstore.Content->NEWS->NEWS.STORY> newsStoryDesc : WilliesPetstore.Content->NEWS->NEWS.STORY{*}){

System.out.println(newsStoryDesc:>Title); System.out.println((newsStoryDesc:>StoryDate).toString()); System.out.println(newsStoryDesc:>StoryContent + "\n"); }

ANNOTATIONS { DEFAULT { return null; } } } AVAILABLE ON HANDOUT}

Page 15: Why Java Needs Hierarchical Data

15

Output from Willie’s Petstore Console App

Willie's Pets and Things

news:Adopt a Pet_________________________________________________________Wed Mar 17 00:00:00 PDT 2010Your chance to adopt a lonely doggie is right around the

corner.

20% off Fanciful Dog Spread_________________________________________________________Wed Mar 10 00:00:00 PST 2010For one day only, come and pick up your tub of Fanciful

Dog Spread!

Page 16: Why Java Needs Hierarchical Data

1616

End of Part 1 – Introduction on How End of Part 1 – Introduction on How to use Hierarchy to use Hierarchy

For more information, you can download For more information, you can download the fairly extensive documentation (and the fairly extensive documentation (and Hierarchy itself) from our website:Hierarchy itself) from our website:http://www.unconventionalthinking.nethttp://www.unconventionalthinking.net

Questions?Questions?

Page 17: Why Java Needs Hierarchical Data

1717

Part 2 – The Benefits of Using Part 2 – The Benefits of Using Hierarchy in Your SystemsHierarchy in Your Systems

……also, techniques to use also, techniques to use hierarchical data effectively in hierarchical data effectively in

system architecturessystem architectures

Page 18: Why Java Needs Hierarchical Data

1818

How is Hierarchy How is Hierarchy Useful?Useful? Think of all the ways we use Think of all the ways we use

hierarchical data in our systems:hierarchical data in our systems:– XML config filesXML config files– DB results returned from DB results returned from

Hibernate/JPA*Hibernate/JPA*(*Not really hierarchical, it’s a map)(*Not really hierarchical, it’s a map)

– SpringSpring– Web ServicesWeb Services– JSON Objects in our JavascriptJSON Objects in our Javascript

Page 19: Why Java Needs Hierarchical Data

1919

Current XML Current XML technologies work technologies work fine, don’t they?fine, don’t they?

JAXB, JAXP, JDOMJAXB, JAXP, JDOM Dedicated Hierarchical Data Dedicated Hierarchical Data

Structure Structure

Hierarchical Data as easy to Hierarchical Data as easy to create as a class.create as a class.

Page 20: Why Java Needs Hierarchical Data

2020

Why use Hierarchy?Why use Hierarchy?

The best of JSON & LINQThe best of JSON & LINQ Quick look at JSON for JavascriptQuick look at JSON for Javascript

{{ "firstName": "John","firstName": "John", "lastName" : "Smith","lastName" : "Smith", "age" : 25,"age" : 25, "address" :"address" : {{ "streetAddress": "21 2nd Street","streetAddress": "21 2nd Street", "city" : "New York","city" : "New York", "state" : "NY","state" : "NY", "postalCode" : "10021""postalCode" : "10021" }}}}

Page 21: Why Java Needs Hierarchical Data

2121

Why use Hierarchy? Why use Hierarchy? (cont)(cont)

Quick look at LINQ for C#.NetQuick look at LINQ for C#.Net

int someValue = 5; int someValue = 5;

var results = from c in SomeCollectionvar results = from c in SomeCollection

where c.SomeProp < someValue * 2where c.SomeProp < someValue * 2

select new {c.SomeProp, c.OtherProp};select new {c.SomeProp, c.OtherProp};

foreach (var result in results) foreach (var result in results)

Console.WriteLine(result);Console.WriteLine(result);

Page 22: Why Java Needs Hierarchical Data

2222

Hierarchy combines the Hierarchy combines the best of both these best of both these technologiestechnologies Adds powerful but simple Adds powerful but simple

hierarchical data-structure to Javahierarchical data-structure to Java Technology with lots of potentialTechnology with lots of potential

Page 23: Why Java Needs Hierarchical Data

2323

Next usage of Hierarchical Next usage of Hierarchical Data:Data:

Universal Data DefinitionUniversal Data Definition

Questions?Questions?

Page 24: Why Java Needs Hierarchical Data

2424

Problems with defining Problems with defining fieldsfields

Ex: Creating an online registration form:Ex: Creating an online registration form:

Enter Your Info:Enter Your Info:

First First namename

Last nameLast name

AddressAddress.

.

.

Page 25: Why Java Needs Hierarchical Data

2525

Fields defined in Fields defined in multiple placesmultiple places

DB

hibernate.cfg.xml

public class MyClass {

String firstName;

String lastName;

}

JSF or JSP or HTML page

Javascript JSON object

Page 26: Why Java Needs Hierarchical Data

2626

Universal Data DefinitionUniversal Data DefinitionDefine all the usages of a field in 1 spot:Define all the usages of a field in 1 spot:MATRIX MyWebApp.Matrix USES (WebForm, Database, JSON) {

`First Name` {FORM.REQUIRED: { +:IsRequired };FORM.CONTROL: { :TextBox, 30 };HELP.TEXT: { “Please enter in your first name” };DB.COLUMN: { +:Customer, +:First_Name, :”VAR_CHAR” };JSON.FIELD: { “myJsonObj”, “firstName”};

}`Last Name` {

FORM.REQUIRED: { +:IsRequired };FORM.INPUT: { :TextBox, 30 };HELP.TEXT: { “Please enter in your last name” };

DB.COLUMN: { +:Customer, +:Last_Name, :String };JSON.FIELD: { “myJsonObj”, “LastName”};

}}

Page 27: Why Java Needs Hierarchical Data

2727

Another look at Another look at previous slide…previous slide…

DB

hibernate.cfg.xml

public class MyClass {

String firstName;

String last Name

}

JSF or JSP or HTML page

Javascript JSON object

Page 28: Why Java Needs Hierarchical Data

2828

Persistence for Persistence for HierarchyHierarchy Not object-relational mapping like Not object-relational mapping like

Hibernate / JPA. It’s a full Hibernate / JPA. It’s a full persistence serverpersistence server

Extremely easy to useExtremely easy to use Working alphaWorking alpha

Page 29: Why Java Needs Hierarchical Data

2929

One Technology for One Technology for multiple usesmultiple uses XML Config filesXML Config files SpringSpring Object-Relational Mapping Object-Relational Mapping

(Hibernate)(Hibernate) True PersistenceTrue Persistence

Page 30: Why Java Needs Hierarchical Data

3030

Future of HierarchyFuture of Hierarchy

Finish Beta 2 fixesFinish Beta 2 fixes

Finish PersistenceFinish Persistence

IDE Integration (Eclipse, Netbeans)IDE Integration (Eclipse, Netbeans)

View Language (Already designed)View Language (Already designed)

LINQ or Hibernate like functionalityLINQ or Hibernate like functionality

Also, remember, Matrices are not static Also, remember, Matrices are not static xml. They are a new data structure in xml. They are a new data structure in Java! More possibilities for new usesJava! More possibilities for new uses

Page 31: Why Java Needs Hierarchical Data

3131

Future of Hierarchy (cont)Future of Hierarchy (cont)Issues to AVOID with User Adoption Issues to AVOID with User Adoption – Poorly implementation & buggyPoorly implementation & buggy– Tough to work withTough to work with– Not enough supporting toolsNot enough supporting tools– Nobody knows about the Hierarchy!Nobody knows about the Hierarchy!

Released open source in the near futureReleased open source in the near future

Only ~30% of what we had plannedOnly ~30% of what we had planned– Excel-like tool for CMSExcel-like tool for CMS– New architectural language elements w/ IDE toolsNew architectural language elements w/ IDE tools– New tools for creating meta-code (like JSP’s)New tools for creating meta-code (like JSP’s)

Contribute your time & Looking for business to Contribute your time & Looking for business to partner with!partner with!

Page 32: Why Java Needs Hierarchical Data

3232

Please Contribute your Please Contribute your Time!Time!

change Javachange Java

Page 33: Why Java Needs Hierarchical Data

3333

Thank you!Thank you!

Optional Extra Material:Optional Extra Material:N-Dimensional ArchitectureN-Dimensional Architecture

Before Proceeding, Before Proceeding,

Any Questions?Any Questions?

Page 34: Why Java Needs Hierarchical Data

3434

New architectures with New architectures with Hierarchical DataHierarchical Data

Collect all the settings and content Collect all the settings and content together in matricestogether in matrices– Similar to what we did in the running Similar to what we did in the running

exampleexample Put things that change the most Put things that change the most

togethertogether Very similar to what happens in SpringVery similar to what happens in Spring Unconventional Thinking website was Unconventional Thinking website was

done using this technique done using this technique ((HandoutHandout))

Page 35: Why Java Needs Hierarchical Data

3535

Real World Results of Real World Results of Collecting Settings into Collecting Settings into MatricesMatrices Easier to maintain – one spot for Easier to maintain – one spot for

all changesall changes System Design tends towards System Design tends towards

automationautomation Simpler architecture, Less codeSimpler architecture, Less code

Page 36: Why Java Needs Hierarchical Data

3636

Past & Current Past & Current ArchitecturesArchitectures Architectures for Structural Architectures for Structural

ProgrammingProgramming Architectures for Object-Oriented Architectures for Object-Oriented

ProgrammingProgramming

Page 37: Why Java Needs Hierarchical Data

Structural-Programming Structural-Programming Sample ArchitectureSample Architecture

main()main() { initialize(); run(); cleanup();}

initialize() run() cleanup()

getConn() gatherNews() formatNews()

News App

Page 38: Why Java Needs Hierarchical Data

3838

Pros & Cons of Pros & Cons of Structural Structural ProgrammingProgramming Pros: Pros:

– Conceptually well organizedConceptually well organized– Easy to NavigateEasy to Navigate

Cons: Cons: – Tend not to be as well organized with Tend not to be as well organized with

larger systems. Not as natural to larger systems. Not as natural to group the functions into modules group the functions into modules compared to OOcompared to OO

– Harder to visualize, so harder to learnHarder to visualize, so harder to learn

Page 39: Why Java Needs Hierarchical Data

Object-Oriented Sample Object-Oriented Sample ArchitectureArchitecture

NewsGatherer

initialize(); gatherNews();

NewsCollection

initialize(); getData();

NewsFormatter

cleanData(); formatData();

NewsDisplay

displayNewsData();

NewsFormatter

cleanData(); formatData();

Model Objects View Objects

Page 40: Why Java Needs Hierarchical Data

4040

Pros & Cons of Object-Pros & Cons of Object-OrientedOriented

Pros: Pros: – Visually, it’s easier to understand. Because the Visually, it’s easier to understand. Because the

different parts of the system are “things.” different parts of the system are “things.” – Objects better define the different Objects better define the different

responsibilities of system.responsibilities of system. Cons: Cons:

– It’s easy to get lost – OO systems can feel like It’s easy to get lost – OO systems can feel like there’s no overall organization of the system.there’s no overall organization of the system.

– Ripple Effect still happens, where you sometimes Ripple Effect still happens, where you sometimes have to make changes up and down the system.have to make changes up and down the system.

Page 41: Why Java Needs Hierarchical Data

N-Dimensional Architecture N-Dimensional Architecture SampleSampleControl Layer

Execution Layer

Services Layer

News Settings – contains settings across entire app

Presentation Cross-Section Business Logic Cross-Section

NewsGatherer Service Gathers news from collections

HTML Table Renderer Displays news in tables

View-Related Services Data-Related Services

NewsView Worker Displays news as HTML

News Scheduler Schedules news gathering

News – wrapper for entire news service

Page 42: Why Java Needs Hierarchical Data

4242

N-Dimensional N-Dimensional Architecture SummaryArchitecture Summary

A new architecture based on our A new architecture based on our research.research.

Organize you system in multiple Organize you system in multiple ways at the same time.ways at the same time.

The technique we spoke about, The technique we spoke about, “Collecting all settings and content “Collecting all settings and content together” is a using this together” is a using this architecture.architecture.

Page 43: Why Java Needs Hierarchical Data

4343

N-Dimensional N-Dimensional Architecture Pros & ConsArchitecture Pros & Cons

ProsPros– Easy of navigability and better sense of Easy of navigability and better sense of

natural layers of systemnatural layers of system– While retaining feel of real world While retaining feel of real world

componentscomponents– Tend to be Tend to be AutomatedAutomated– Tend to be Tend to be Developer-OrientedDeveloper-Oriented

ConsCons– Not as useful for libraries and servicesNot as useful for libraries and services

Page 44: Why Java Needs Hierarchical Data

4444

Thank You Thank You

Q & AQ & Aandand

Discussion About Taking on Discussion About Taking on your Own Software Ideasyour Own Software Ideas

Peter JohPeter [email protected]@unconventionalthinking.netwww.unconventionalthinking.netwww.unconventionalthinking.net