Skip to content

🐉 Solved problems demonstrating the use of Factory, Singleton and Strategy Design Patterns using Java. These problems were solved during the course "Object Oriented Analysis and Design CS309"

License

Notifications You must be signed in to change notification settings

OSSpk/Factory-Singleton-and-Strategy-Design-Patterns_Examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Examples Demonstrating Factory, Singleton and Strategy Design Patterns 🐉

views Open Source Love svg1 GitHub Forks GitHub Issues contributions welcome

To study more about Design Patterns, visit Source Making Design Patterns

Factory Method

Q1: In a ‘Drawing’ system, depending on user’s input, different pictures like square, rectangle, circle can be drawn. Here we can use factory method to create instances depending on user’s input. For adding new type of shape, no need to change client’s code.

Q2: In travel site, we can book train ticket as well bus tickets and flight ticket. In this case user can give his travel type as ‘bus’, ‘train’ or ‘flight’. Here we have an abstract class ‘AnyTravel’ with a static member function ‘GetObject’ which depending on user’s travel type, will create & return object of ‘BusTravel’ or ‘ TrainTravel’. ‘BusTravel’ or ‘ TrainTravel’ have common functions like passenger name, Origin, destination parameters.

Strategy and Singleton Patterns

Q. You are asked to develop a mobile application for a Famous Shopping Cart system. This application has the option for the user to shop in either an online mode or in an offline mode. If the user is connected to the network, your application would fetch the product list from the server, which will be called by the NetworkManager and if the user is not connected to the server the product list will be fetched from local database using DatabaseManager. You have a product object which contains product id, name and price. The database manager and network manager has one method getProductList which will return array of products.

Note: You will require a global method in your main named bool checkAccessibility() it will return true if internet is connected and false if internet is not connected

Hint: Use singleton and strategy pattern.

How to Run

1- Install these:

2- Open NetBeans IDE. Click on File -> Open Project and browse to the project you want to open say "Factory Method" and select it. It will load the NetBeans project. (There are basically two separate NetBeans Projects named Factory Method and Strategy and Singleton Patterns)


Author

You can get in touch with me on my LinkedIn Profile: LinkedIn Link

You can also follow my GitHub Profile to stay updated about my latest projects: GitHub Follow

If you liked the repo then kindly support it by giving it a star ⭐ and share in your circles so more people can benefit from the effort.

Contributions Welcome

GitHub Issues

If you find any bugs, have suggestions, or face issues:

  • Open an Issue in the Issues Tab to discuss them.
  • Submit a Pull Request to propose fixes or improvements.
  • Review Pull Requests from other contributors to help maintain the project's quality and progress.

This project thrives on community collaboration! Members are encouraged to take the initiative, support one another, and actively engage in all aspects of the project. Whether it’s debugging, fixing issues, or brainstorming new ideas, your contributions are what keep this project moving forward.

With modern AI tools like ChatGPT, solving challenges and contributing effectively is easier than ever. Let’s work together to make this project the best it can be! 🚀

License

MIT

Copyright (c) 2018-present, harismuneer


Waving hand Hey there, I'm Haris Muneer 👨🏻‍💻

Total Github Stars Total Github Followers


  • 🕸️ Founder of Cyfy Labs: At Cyfy Labs, we provide advanced social media scraping tools to help businesses, researchers, and marketers extract actionable data from platforms like Facebook, Instagram, and X (formerly Twitter). Our tools support lead generation, sentiment analysis, market research, and various other use cases. To learn more, visit: www.cyfylabs.com

  • 🌟 Open Source Advocate: I’m passionate about making tech accessible. I’ve open-sourced several projects that you can explore on my GitHub profile and on the Open Source Software PK page.

  • 📫 How to Reach Me: You can learn more about my skills/work at LinkedIn. You can also reach out via email for collaboration or inquiries. For Cyfy Labs related queries, please reach out through the company website.


🤝 Follow my journey

About

🐉 Solved problems demonstrating the use of Factory, Singleton and Strategy Design Patterns using Java. These problems were solved during the course "Object Oriented Analysis and Design CS309"

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Languages