Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7620723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:00:26+00:00 2026-05-31T04:00:26+00:00

I have this class that tries multiple methods of getting data from Google maps

  • 0

I have this class that tries multiple methods of getting data from Google maps web services API.

If one method fails, it tries another. etc.

Something like this (pseudo code):

FUNCTION FIND_ADDRESS( house_number, postcode )

    get location co-ordinates for postcode from local database

    if location returns false, try getting location from maps service

    if map service fails, return "postcode not found", exit

    get address components using location co-ordinates

    if address components doesn't contain street name, return street name not found, exit

    if street name exists, get all address_components + location for house number, street_name and postcode

    if no results, try again without the postcode,

    if still no results, return location co-ordinates for postcode found earlier in code

END

As you can see, This is very procedural!

I’m trying to think of ways to improve the code, and I’ve externalised all re-usable code, added exception handling to know exactly where the code fails if it does.

But I was wondering if anybody knows of a design pattern or similar solution.

Because I’m basically trying something, if it fails trying something else, if it fails trying something else and so on until I get a full address

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:00:28+00:00Added an answer on May 31, 2026 at 4:00 am

    You might want to look into Chain of Responsibility.

    In Object Oriented Design, the chain-of-responsibility pattern is a design pattern consisting of a source of command objects and a series of processing objects. Each processing object contains logic that defines the types of command objects that it can handle; the rest are passed to the next processing object in the chain. A mechanism also exists for adding new processing objects to the end of this chain.

    So instead of having many if/else or try/catch blocks, you do something like

    $finderChain = new AddressFinder;
    $finder
        ->add(new LocalFinder)
        ->add(new MapsService)
        ->add(…);
    
    $result = $finder->find($houseNo, $postCode);
    

    Internally, you will send $houseNo and $postCode to the LocalFinder. If it doesn’t find the desired data, the next element in the chain is tasked with trying to find the desired data. This is repeated until either the end of the chain is reached or the desired data was produced.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that contains data from some model. This class has metadata
I have this class that contains vars for db connection; Imports Microsoft.VisualBasic Imports System.Data.SqlClient
I have this class that have a function to load other classes and create
I have this class called PollFrame that extends JFrame in a file called PollFrame.java
I have this code inside a class that is used by an application and
I have this small class called City that simply holds some information about a
Assume I have a class that looks like this: class Sample { public string
I have a custom class that implements that IComparable. This class is stored in
I have a custom class that implements ICollection , and this class is readonly,
I have a generic class that takes a type T . Within this class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.