DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • What Is JHipster?
  • Building the World's Most Resilient To-Do List Application With Node.js, K8s, and Distributed SQL
  • AI and Cybersecurity Protecting Against Emerging Threats
  • Rule-Based Prompts: How To Streamline Error Handling and Boost Team Efficiency With ChatGPT

Trending

  • What Is JHipster?
  • Building the World's Most Resilient To-Do List Application With Node.js, K8s, and Distributed SQL
  • AI and Cybersecurity Protecting Against Emerging Threats
  • Rule-Based Prompts: How To Streamline Error Handling and Boost Team Efficiency With ChatGPT

Create Your Own DSL

Alexey Kutuzov user avatar by
Alexey Kutuzov
·
Jul. 31, 13 · Interview
Like (0)
Save
Tweet
Share
6.63K Views

Join the DZone community and get the full member experience.

Join For Free

In software development I encounter problems with creating user interfaces for manage logical chains. More complex chain of logic cause more difficult to develop, test, and debug resulting interface. That interfaces are hard to understand without help of man, who participated in the design.

Usually, it looks like that: 


Instead of complex interface is to try to use DSL. This require a little more skill from the end user but in return it will eliminate the overloaded ui. It provide a more flexible control over logic at lower labor costs. A much easier debugging, testing, and auto-testing.

Consider the example of pethouse. We have the following classes:

class Food {
    Integer size
}
class Pet {
    String name
    Long age
    Closure hello
}
@DSLRoot("pet_house")
class PetHouse {
    String name
    Pet master
    @DSLTypeHint(Pet) List<Pet> pet
    @DSLTypeHint(Food) Map<String, Food> food
}

To create pethouse we need one screen to PetHouse and two dialogue to Pet and Food. The difficulties begin with the behavior of hello method for each pet. How many screens needed if we want to pet shouted "Hello!" only when there is enough food for it? And if we want to check whether a particular type of food?

All this logic is easy to describe in the DSL (groovy):

pet_house {
    name "My pet house"
    food {
        cat_food {size 12}
    }
    pet {
        name "Cat"
        hello {
            if (food["cat_food"].size > 0) {
                return "Hello"
            } else {
                return "I need food!!!"
            }
        }
    }
}

Plain and simple.

There is DSLParser with specification to help write your own DSL. Also, it requires Reflections which can be replaced simply.

DSLParser (github) (include spec)

Domain-Specific Language

Published at DZone with permission of Alexey Kutuzov. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • What Is JHipster?
  • Building the World's Most Resilient To-Do List Application With Node.js, K8s, and Distributed SQL
  • AI and Cybersecurity Protecting Against Emerging Threats
  • Rule-Based Prompts: How To Streamline Error Handling and Boost Team Efficiency With ChatGPT

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: