iPhonicalSoftware Development
and Model-Driven


Heiko Behrens (itemis)




backchannel via #iphonical #iphonedevcon09
/ soft·ware de·vel·op·ment / n.
the set of activities that results in
software products. ~ may include
research, new development,
modification, reuse, maintenance,
or any other activities that result in
software products.
Sketching some

      Typical Situations
              in
    Software Development

                 #iphonical #iphonedevcon09
Boring code
Accidental complexity
Wrong level of abstraction
Anatomy of Modern Software




         Software artifact
Anatomy of Modern Software




    manually written code      Frameworks




                   Libraries
Anatomy of Modern Software


                    manually written
                        code

                                       Frameworks

  schematic code (manually written)



                       Libraries
(rote) coding doesn’t cut it!
Our Problems




Can we solve them with code generation?
Yes, we can!
Talking about

    Common Approaches
             to
     Advoid Redundancy

                #iphonical #iphonedevcon09
Wizards
Wizards in Practice



Ruby on Rails      AppLoop


     Xcode Project Templates
This wizard whips up a
complete and running
legacy application with
just a single click.
Designers
Designers in Practice


              Graphical
              Designers


  Interface               Core
  Builder                 Data
Interface Builder
is no abstraction
 but another approach
  to object construction.
   Handwritten code is
   still needed.
Core Data
 produces code a
  developer can work
   with but overwrites
 handcrafted value.
Introducing

       Model-Driven
   Software Development
                              #mdsd
              #iphonical #iphonedevcon09
Raise the level
of abstraction
where possible
and generate
 code wisely.
One cannot
  abstract away
   everything.
 Manual code is
 great for all the
special cases and
     details.
Use the best of both worlds at the same time.
Isn’t
        Core Data
                           #mdsd?
             #iphonical #iphonedevcon09
Models Data Schema
Sophisticated Runtime
Demo
So, what’s
             # iPhonical
                                about?
                           #iphonedevcon09
View DSL                     View / GUI              NIB



 Entity DSL

                            ViewController       ViewController
Remote DSL



Service DSL
                                                 Transfomer
                            ServiceFacades
                                                   Mapper




ORM / DAO                                                         RemoteClient
                 Entities                  Messages




  Sqlite                                     JSON                    HTTP




                 Any
                                                        ServerFacade
              RestService


                                                Server                Server
                                                Entities             Messages


                                                       JBoss / RestEasy
Thoughts of an iPhone developer
View DSL                     View / GUI              NIB



 Entity DSL
                                 Better
                                Manually
                            ViewController       ViewController
Remote DSL



Service DSL

                            What’s this?
                                                 Transfomer
                            ServiceFacades
                                                   Mapper




  Core Data
ORM / DAO
                 Entities
                                             Framework
                                           Messages
                                                                  RemoteClient




  Sqlite                                     JSON                    HTTP




                 Any
                                                        ServerFacade
              RestService

                                               Most likely
                                                Server
                                                Entities
                                                                      Server
                                                                     Messages

                                                legacy JBoss / RestEasy
Will now present
      Objective Resource
                 or
       “iPhone on Rails”
           #iphonical #iphonedevcon09
Demo
Entities with Objective Resource
#import "ObjectiveResource.h"                                  #import "ObjectiveResource.h"
#import "Dog.h"                                                #import "Person.h"

@interface Person : NSObject {                                 @implementation Person
! NSString *personId;                                          @synthesize personId;
! NSDate *updatedAt;                                           @synthesize updatedAt;
! NSDate *createdAt;                                           @synthesize createdAt;
! NSString *name;                                              @synthesize name;
}
                                                               // handle pluralization
@property   (nonatomic,   retain)   NSString *personId;        + (NSString *) getRemoteCollectionName {
@property   (nonatomic,   retain)   NSDate *updatedAt;         ! return @"people";
@property   (nonatomic,   retain)   NSDate *createdAt;         }
@property   (nonatomic,   retain)   NSString *name;
                                                               - (NSArray *) findAllDogs {
// returns dogs                                                ! return [Dog findRemote:[NSString stringWithFormat:
- (NSArray *) findAllDogs;                                            @"%@/dogs", personId, nil]];
- (NSArray *) findAllDogsWithResponse: (NSError * *) aError;   }

@end                                                           - (NSArray *) findAllDogsWithResponse: (NSError * *) aError {
                                                               ! return [Dog findRemote:[NSString stringWithFormat:
                                                                      @"%@/dogs", personId, nil] withResponse: aError];
                                                               }

                                                               - (void) dealloc {
                                                               ! [personId release];
                                                               ! [updatedAt release];
                                                               ! [createdAt release];
                                                               ! [name release];
                                                               ! [super dealloc];
                                                               }

                                                               @end
Real Information Content
#import "ObjectiveResource.h"                                  #import "ObjectiveResource.h"
#import "Dog.h"                                                #import "Person.h"

@interface Person : NSObject {                                 @implementation Person
! NSString *personId;                                          @synthesize personId;
! NSDate *updatedAt;                                           @synthesize updatedAt;
! NSDate *createdAt;                                           @synthesize createdAt;
! NSString *name;                                              @synthesize name;
}
                                                               // handle pluralization
@property   (nonatomic,   retain)   NSString *personId;        + (NSString *) getRemoteCollectionName {
@property   (nonatomic,   retain)   NSDate *updatedAt;         ! return @"people";
@property   (nonatomic,   retain)   NSDate *createdAt;         }
@property   (nonatomic,   retain)   NSString *name;
                                                               - (NSArray *) findAllDogs {
// returns dogs                                                ! return [Dog findRemote:[NSString stringWithFormat:
- (NSArray *) findAllDogs;                                            @"%@/dogs", personId, nil]];
- (NSArray *) findAllDogsWithResponse: (NSError * *) aError;   }

@end                                                           - (NSArray *) findAllDogsWithResponse: (NSError * *) aError {
                                                               ! return [Dog findRemote:[NSString stringWithFormat:
                                                                      @"%@/dogs", personId, nil] withResponse: aError];
                                                               }

                                                               - (void) dealloc {
                                                               ! [personId release];
                                                               ! [updatedAt release];
                                                               ! [createdAt release];
                                                               ! [name release];
                                                               ! [super dealloc];
                                                               }

                                                               @end
Objective-C #ftl ?
       #iphonical #iphonedevcon09
Objective-C
Suppose...
You’d want to core an apple...
... for your kids.
?
Right tool for the job
Your trusty swiss army knife!
Suppose...
You’d want to core a few more apples...
... for an apple cake.
Still the best tool for the job?
Better use this one
...and this one
... a DSL is ...
A specific tool
for a specific job
A specific tool
for a specific job
Idea behind #iphonical :

Use DSLs to describe the world

                          #iphonedevcon09
!   !   entity Car {
!   !   ! ! ! ! String name;
!   !   ! ! ! ! String number;
!   !   ! ! ! ! Integer km;
!   !   ! ! ! ! JourneyEntry * journeys;
!   !   };
!   !
!
!
!
    !
    !
    !
        entity JourneyEntry {
        ! ! ! ! Location startLocation;
                                                          Entities
!   !   ! ! ! ! Location endLocation;
!   !   ! ! ! ! String comment;
!   !   ! ! ! ! Integer startKm;
!   !   ! ! ! ! Integer endKm;
!   !   ! ! ! ! Car car;
!   !   ! ! ! ! Driver driver;
!   !   ! ! ! ! Reason reason;
!   !   };


!   !   entity CarDataResponse {
!   !   ! ! ! ! String creationDate;
!
!
!
    !
    !
    !
        ! ! ! ! Car car;
        ! ! ! ! Location location;
        ! ! ! ! JourneyEntry journey;
                                             Services / Messages
!   !   ! ! ! ! Driver driver;
!   !   };

!   !   restService iDriveLogService "/idrivelogservice" {
!   !   ! ! ! ! baseUrl "http://localhost:8080/iDriveLogRESTWebServices";
!   !   ! ! ! ! get data "/data" response:CarDataResponse;
!   !   };




!   !   viewController Root {


                                                               UI
!   !   ! ! ! ! ui Label myLabel;
!   !   ! ! ! ! ui Textfield myTextfield;
!   !   ! ! ! ! action myAction;
!   !   };
Leverage Entity DSL
        for
Objective Resource
View / GUI



Entity DSL

                ViewController




             Objective Resource


                 Entities and
                  Mapping




                 JSON / HTTP




                    Rails
                  Application
Demo
Wait...

  #iPhonical works
 with any framework
                     ?
               #iphonedevcon09
Demo of custom templates
#iPhonical: Where to get
        and its future
              #iphonedevcon09
Open source Apache License 2.0


                        code
       code.google.com/p/iphonical/



          Currently 8 participants
What’s comming up?

! Publications in upcoming
  Eclipse Magazin
! ShowCase about Conferences
! Tighter integration with Xcode
twitter @HBehrens
blog http://HeikoBehrens.net

mail       Heiko.Behrens@itemis.de
xing       http://www.xing.com/profile/Heiko_Behrens
linkedin   http://www.linkedin.com/in/HeikoBehrens




                                                      code.google.com/p/iphonical

iPhonical and model-driven software development for the iPhone

  • 1.
    iPhonicalSoftware Development and Model-Driven HeikoBehrens (itemis) backchannel via #iphonical #iphonedevcon09
  • 2.
    / soft·ware de·vel·op·ment/ n. the set of activities that results in software products. ~ may include research, new development, modification, reuse, maintenance, or any other activities that result in software products.
  • 3.
    Sketching some Typical Situations in Software Development #iphonical #iphonedevcon09
  • 4.
  • 5.
  • 6.
    Wrong level ofabstraction
  • 7.
    Anatomy of ModernSoftware Software artifact
  • 8.
    Anatomy of ModernSoftware manually written code Frameworks Libraries
  • 9.
    Anatomy of ModernSoftware manually written code Frameworks schematic code (manually written) Libraries
  • 10.
  • 11.
    Our Problems Can wesolve them with code generation?
  • 12.
  • 13.
    Talking about Common Approaches to Advoid Redundancy #iphonical #iphonedevcon09
  • 14.
  • 15.
    Wizards in Practice Rubyon Rails AppLoop Xcode Project Templates
  • 16.
    This wizard whipsup a complete and running legacy application with just a single click.
  • 17.
  • 18.
    Designers in Practice Graphical Designers Interface Core Builder Data
  • 19.
    Interface Builder is noabstraction but another approach to object construction. Handwritten code is still needed.
  • 20.
    Core Data producescode a developer can work with but overwrites handcrafted value.
  • 21.
    Introducing Model-Driven Software Development #mdsd #iphonical #iphonedevcon09
  • 22.
    Raise the level ofabstraction where possible and generate code wisely.
  • 23.
    One cannot abstract away everything. Manual code is great for all the special cases and details.
  • 24.
    Use the bestof both worlds at the same time.
  • 25.
    Isn’t Core Data #mdsd? #iphonical #iphonedevcon09
  • 26.
  • 27.
  • 28.
  • 29.
    So, what’s # iPhonical about? #iphonedevcon09
  • 30.
    View DSL View / GUI NIB Entity DSL ViewController ViewController Remote DSL Service DSL Transfomer ServiceFacades Mapper ORM / DAO RemoteClient Entities Messages Sqlite JSON HTTP Any ServerFacade RestService Server Server Entities Messages JBoss / RestEasy
  • 31.
    Thoughts of aniPhone developer
  • 32.
    View DSL View / GUI NIB Entity DSL Better Manually ViewController ViewController Remote DSL Service DSL What’s this? Transfomer ServiceFacades Mapper Core Data ORM / DAO Entities Framework Messages RemoteClient Sqlite JSON HTTP Any ServerFacade RestService Most likely Server Entities Server Messages legacy JBoss / RestEasy
  • 33.
    Will now present Objective Resource or “iPhone on Rails” #iphonical #iphonedevcon09
  • 34.
  • 35.
    Entities with ObjectiveResource #import "ObjectiveResource.h" #import "ObjectiveResource.h" #import "Dog.h" #import "Person.h" @interface Person : NSObject { @implementation Person ! NSString *personId; @synthesize personId; ! NSDate *updatedAt; @synthesize updatedAt; ! NSDate *createdAt; @synthesize createdAt; ! NSString *name; @synthesize name; } // handle pluralization @property (nonatomic, retain) NSString *personId; + (NSString *) getRemoteCollectionName { @property (nonatomic, retain) NSDate *updatedAt; ! return @"people"; @property (nonatomic, retain) NSDate *createdAt; } @property (nonatomic, retain) NSString *name; - (NSArray *) findAllDogs { // returns dogs ! return [Dog findRemote:[NSString stringWithFormat: - (NSArray *) findAllDogs; @"%@/dogs", personId, nil]]; - (NSArray *) findAllDogsWithResponse: (NSError * *) aError; } @end - (NSArray *) findAllDogsWithResponse: (NSError * *) aError { ! return [Dog findRemote:[NSString stringWithFormat: @"%@/dogs", personId, nil] withResponse: aError]; } - (void) dealloc { ! [personId release]; ! [updatedAt release]; ! [createdAt release]; ! [name release]; ! [super dealloc]; } @end
  • 36.
    Real Information Content #import"ObjectiveResource.h" #import "ObjectiveResource.h" #import "Dog.h" #import "Person.h" @interface Person : NSObject { @implementation Person ! NSString *personId; @synthesize personId; ! NSDate *updatedAt; @synthesize updatedAt; ! NSDate *createdAt; @synthesize createdAt; ! NSString *name; @synthesize name; } // handle pluralization @property (nonatomic, retain) NSString *personId; + (NSString *) getRemoteCollectionName { @property (nonatomic, retain) NSDate *updatedAt; ! return @"people"; @property (nonatomic, retain) NSDate *createdAt; } @property (nonatomic, retain) NSString *name; - (NSArray *) findAllDogs { // returns dogs ! return [Dog findRemote:[NSString stringWithFormat: - (NSArray *) findAllDogs; @"%@/dogs", personId, nil]]; - (NSArray *) findAllDogsWithResponse: (NSError * *) aError; } @end - (NSArray *) findAllDogsWithResponse: (NSError * *) aError { ! return [Dog findRemote:[NSString stringWithFormat: @"%@/dogs", personId, nil] withResponse: aError]; } - (void) dealloc { ! [personId release]; ! [updatedAt release]; ! [createdAt release]; ! [name release]; ! [super dealloc]; } @end
  • 37.
    Objective-C #ftl ? #iphonical #iphonedevcon09
  • 38.
  • 39.
  • 40.
    You’d want tocore an apple...
  • 41.
  • 42.
  • 43.
    Your trusty swissarmy knife!
  • 44.
  • 45.
    You’d want tocore a few more apples...
  • 46.
    ... for anapple cake.
  • 47.
    Still the besttool for the job?
  • 48.
  • 49.
  • 50.
    ... a DSLis ...
  • 51.
    A specific tool fora specific job
  • 52.
    A specific tool fora specific job
  • 53.
    Idea behind #iphonical: Use DSLs to describe the world #iphonedevcon09
  • 54.
    ! ! entity Car { ! ! ! ! ! ! String name; ! ! ! ! ! ! String number; ! ! ! ! ! ! Integer km; ! ! ! ! ! ! JourneyEntry * journeys; ! ! }; ! ! ! ! ! ! ! ! entity JourneyEntry { ! ! ! ! Location startLocation; Entities ! ! ! ! ! ! Location endLocation; ! ! ! ! ! ! String comment; ! ! ! ! ! ! Integer startKm; ! ! ! ! ! ! Integer endKm; ! ! ! ! ! ! Car car; ! ! ! ! ! ! Driver driver; ! ! ! ! ! ! Reason reason; ! ! }; ! ! entity CarDataResponse { ! ! ! ! ! ! String creationDate; ! ! ! ! ! ! ! ! ! ! Car car; ! ! ! ! Location location; ! ! ! ! JourneyEntry journey; Services / Messages ! ! ! ! ! ! Driver driver; ! ! }; ! ! restService iDriveLogService "/idrivelogservice" { ! ! ! ! ! ! baseUrl "http://localhost:8080/iDriveLogRESTWebServices"; ! ! ! ! ! ! get data "/data" response:CarDataResponse; ! ! }; ! ! viewController Root { UI ! ! ! ! ! ! ui Label myLabel; ! ! ! ! ! ! ui Textfield myTextfield; ! ! ! ! ! ! action myAction; ! ! };
  • 55.
    Leverage Entity DSL for Objective Resource
  • 56.
    View / GUI EntityDSL ViewController Objective Resource Entities and Mapping JSON / HTTP Rails Application
  • 57.
  • 58.
    Wait... #iPhonicalworks with any framework ? #iphonedevcon09
  • 59.
    Demo of customtemplates
  • 60.
    #iPhonical: Where toget and its future #iphonedevcon09
  • 61.
    Open source ApacheLicense 2.0 code code.google.com/p/iphonical/ Currently 8 participants
  • 62.
    What’s comming up? !Publications in upcoming Eclipse Magazin ! ShowCase about Conferences ! Tighter integration with Xcode
  • 63.
    twitter @HBehrens blog http://HeikoBehrens.net mail Heiko.Behrens@itemis.de xing http://www.xing.com/profile/Heiko_Behrens linkedin http://www.linkedin.com/in/HeikoBehrens code.google.com/p/iphonical