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 Video Library
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
View Events Video Library
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
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

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • MuleSoft: Tactical and Strategical Role of an Application Template
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)
  • Common Problems in React Native Apps on iOS Platform: Solutions and Tips
  • How To Verify Database Connection From a Spring Boot Application

Trending

  • Log Analysis: How to Digest 15 Billion Logs Per Day and Keep Big Queries Within 1 Second
  • Using Open Source for Data Integration and Automated Synchronizations
  • Beyond the Prompt: Unmasking Prompt Injections in Large Language Models
  • What Is GitOps?

Limit your abstractions: Application Events–Proposed Solution #2–Cohesion

Oren Eini user avatar by
Oren Eini
·
Feb. 11, 12 · News
Like (0)
Save
Tweet
Share
2.21K Views

Join the DZone community and get the full member experience.

Join For Free

in my previous post, i spoke about isp and how we can replace the following code with something that is easier to follow:

image_thumb3_thumb

i proposed something like:

public interface ihappenon<t>
{
   void inspect(t item);
}

which would be invoked using:

container.executeall<ihappenon<cargo>>(i=>i.inspect(cargo));

or something like that.

which lead us to the following code:

public class cargoarrived : ihappenedon<cargo>
{
  public void inspect(cargo cargo)
  {
    if(cargo.delivery.unloadedatdestination == false)
      return;
      
    // handle event
  }
}

public class cargomisdirected : ihappenedon<cargo>
{
  public void inspect(cargo cargo)
  {
    if(cargo.delivery.misdirected == false)
      return;
      
    // handle event
  }
}

public class cargohandled : ihappenon<handlingevent>
{
   // etc
}

public class eventregistrationattempt : ihappenedon<handlingeventregistrationattempt>
{
  // etc
}

but i don’t really like this code, to be perfectly frank. it seems to me like there isn’t really a good reason why cargoarrived and cargomisdirected are located in different classes. it is likely that there is going to be a lot of commonalities between the different types of handling events on cargo. we might as well merge them together for now, giving us:

public class cargohappened : ihappenedon<cargo>
{
  public void inspect(cargo cargo)
  {
    if(cargo.delivery.unloadedatdestination)
      cargoarrived(cargo);
      
    
    if(cargo.delivery.misdirected)
      cargomisdirected(cargo);
      
  }
  
  public void cargoarrived(cargo cargo)
  {
    // handle event
  }
  
  public void cargomisdirected(cargo cargo)
  {
    //handle event
  }
}

this code put a lot of the cargo handling in one place, making it easier to follow and understand. at the same time, the architecture gives us the option to split it to different classes at any time. we aren’t going to end up with a god class for cargo handling. but as long as it make sense, we can keep them together.

i like this style of event processing, but we can probably do better job at if if we actually used event processing semantics here. i’ll discuss that in my next post.

application

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

Opinions expressed by DZone contributors are their own.

Related

  • MuleSoft: Tactical and Strategical Role of an Application Template
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)
  • Common Problems in React Native Apps on iOS Platform: Solutions and Tips
  • How To Verify Database Connection From a Spring Boot Application

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

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: