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 6603849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:04:15+00:00 2026-05-25T19:04:15+00:00

I am trying to create a flyweight object in Java. I’ve worked with a

  • 0

I am trying to create a flyweight object in Java. I’ve worked with a similar concept in Objective-C (Singleton Classes in Objective-C // I believe they are the same thing).

I am trying to find a tutorial or an example or explanation online to learn how to create a flyweight object and use it, but I’ve searched on Google and I can’t find anything descent. I went through 10 pages and they basically all plagiarize from one website which just explains the concept. I understand the concept – I need something to help me/teach me how to implement it in Java.

Anyone has any suggestions/tutorials?

Thanks!

  • 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-25T19:04:15+00:00Added an answer on May 25, 2026 at 7:04 pm

    The Wikipedia entry for the flyweight pattern has a concrete Java example.

    EDIT to try and help the OP understand the pattern:

    As noted in my comment below, The point of the flyweight pattern is that you’re sharing a single instance of something rather than creating new, identical objects.

    Using the Wiki example, the CoffeeFlavorFactory will only create a single instance of any given CoffeeFlavor (this is done the first time a Flavor is requested). Subsequent requests for the same flavor return a reference to the original, single instance.

    public static void main(String[] args) 
    {
        flavorFactory = new CoffeeFlavorFactory();
        CoffeeFlavor a = flavorFactory.getCoffeeFlavor("espresso");
        CoffeeFlavor b = flavorFactory.getCoffeeFlavor("espresso");
        CoffeeFlavor c = flavorFactory.getCoffeeFlavor("espresso");
    
        // This is comparing the reference value, not the contents of the objects
        if (a == b && b == c)
            System.out.println("I have three references to the same object!");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create a user account in a test. But getting a Object reference
I'm trying create a new file with a Java Applet, but I don't know
Trying to create an iPhone app (Objective-C) for my school. I want it to
Trying to create an object from an HQL query, but just can't figure out
I'm trying create an immutable object and initialise it from xml config file in
I'm coding in Objective-C for the iPhone and I am trying create an array
I am trying create a WCF service that leverages the WPF MediaPlayer on the
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
Ok so I am trying create a login script, here I am using PHP5

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.