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
11 Monitoring and Observability Tools for 2023
Learn more
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Maintenance
  4. Limiting abstractions: The key is in the infrastructure

Limiting abstractions: The key is in the infrastructure

Oren Eini user avatar by
Oren Eini
·
Mar. 10, 12 · Interview
Like (0)
Save
Tweet
Share
3.50K Views

Join the DZone community and get the full member experience.

Join For Free

in my previous post, i discussed actual refactoring to reduce abstraction, and i showed two very interesting methods, query() and executecommand(). here is the code in question:

[acceptverbs(httpverbs.post)]
public actionresult register(string originunlocode, string destinationunlocode, datetime arrivaldeadline)
{
    var trackingid = executecommand(new registercargo
    {
        origincode = originunlocode,
        destinationcode = destinationunlocode,
        arrivaldeadline = arrivaldeadline
    });

    return redirecttoaction(showactionname, new routevaluedictionary(new { trackingid }));
}

public class registercargo : command<string>
{
    public override void execute()
    {
        var origin = session.load<location>(origincode);
        var destination = session.load<location>(destinationcode);

        var trackingid = query(new nexttrackingidquery());

        var routespecification = new routespecification(origin, destination, arrivaldeadline);
        var cargo = new cargo(trackingid, routespecification);
        session.save(cargo);

        result = trackingid;
    }

    public string origincode { get; set; }

    public string destinationcode { get; set; }

    public datetime arrivaldeadline { get; set; }

}

what are they so important? mostly because those methods [and similar, like raise(event) and executelater(task)] are actually the back bone of the application. they are the infrastructure on top of which everything rests.

those methods basically accept an argument (and optionally return a value). their responsibility are:

  • setup the given argument so it can run.
  • execute it.
  • return the result (if there is one).

here is an example showing how to implement executecommand:

protected void default_executecommand(command cmd)
{
    cmd.session = session;
    cmd.execute();
}

protected tresult default_executecommand<tresult>(command<tresult> cmd)
{
    executecommand((command) cmd);
    return cmd.result;

}

i have code very much like that in production , because i know that in this system, there are actually only one or two dependencies that a command may want.

there are very few other dependencies, because of the limited number of abstractions that we have. this makes things very simple to write and work with.

because we abstract away any dependency management, and because we allow only very small number of abstractions, this works very well. the amount of complexity that you have is way down, code reviewing this is very easy, because there isn’t much to review, and it all follows the same structure. the implementation of the rest are pretty much the same thing.

there is just one thing left to discuss, because it kept showing up on the comments for the other posts. how do you handle testing?

Abstraction (computer science) Infrastructure

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Build an Automated Testing Pipeline With GitLab CI/CD and Selenium Grid
  • Fixing Bottlenecks in Your Microservices App Flows
  • How To Create a Failover Client Using the Hazelcast Viridian Serverless
  • Microservices 101: Transactional Outbox and Inbox

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
  • +1 (919) 678-0300

Let's be friends: