In this design patterns in java series, I will be documenting the most common design patterns as written by the Gang of Four in their classic book: Design Patterns – Elements of Reusable Object-oriented Software.
I will maintain a pattern (no pun intended) of giving a real-world example then show you the code example. Ready? Let us do this!
Real World Example
Design patterns are everywhere in our lives. For example, a newspaper publishing company releases papers each morning and the papers are delivered to their customers/readers by the good old paper boys! So, the company will keep a list of newspaper subscribers in their database somewhere! The readers are free to subscribe to or unsubscribe from the service if you are tired or when money runs out! Makes sense right?
Food Saver app enables anyone to fight hunger now – yes, immediately, by providing you with 15 closest food collection centers based on your GPS coordinates. I will describe the key features later in a video demo below but for now, let me tell you a bit about why this is one of the most important projects I have solely worked on. Here is how the home screen looks like – watch video below this post for a demo:
Let’s learn how to share an image on Facebook in Android using their ever-changing API. If you have used Facebook’s Android SDK, you know it can be a PITA to say the least. I think Mark should give the developers a vacation for heck’s sake!
How To Share An Image On Facebook In Android – Sample Code
Before you can use Facebook’s Android SDK in your Android application (to add features like sharing, liking etc), you have several options of including their SDK in your project. For instance:
Android swipe views provide lateral navigation between sibling screens such as tabs with a horizontal finger gesture (a pattern sometimes known as horizontal paging). In this post, I will be using a simple android app that I created this past weekend to show you how to create android swipe views. If you have used many android apps, there is a good chance you have seen android swipe views. If not, well, this is your chance to try them. So, here is how the app looks like using swipe views.
An android app prototype can be helpful when you want to build your next android app. Often, jumping straight to code is not the best thing to do, regardless of your experience developing applications. That being said however, sometimes the cost of prototyping tools is out of reach for many starting developers. Before Photoshop started offering their software for a monthly fee, you had to pay a huge amount to get it. If you do not want to pay that much money, Google Docs Drawing tool is your friend. All you need is creativity and time.
Simple Factory Design Pattern is one of the many design patterns – best practices on how to solve common problems. Design Patterns were made popular by the Gang of Four (GoF) – Ralph Johnson, John Vlissides, Richard Helm, and Erich Gamma in their book Design Patterns: Elements of Reusable Object-Oriented Software. In this post, I will show you how to use the Simple Factory Design Pattern.
Simple Factory Design Pattern In Java – Example Code
In order to use simple factory design pattern, you need at least the following classes:
NetworkOnMainThreadException is a pretty popular exception among those new to android development. This exception is mainly thrown whenever an application attempts to make a networking operation (like an API call or Http request) on its main thread. The other aspect of this exception is that it is only thrown by applications targeting the Honeycomb SDK or higher. That means that anything below that will allow you to make network operations or requests in your main thread without causing the popular “YourAppName has stopped working …force close or wait” message. In this post, I will show you how to solve this problem once and for all.
Access modifiers in Java helps us choose what to share with the world and what to keep to ourselves; you know, like your secrets. Perhaps you use them everyday; you know everything you need. Perhaps you are still unsure what they really mean. It does not hurt to refresh your mind because you really can’t know enough. That is why am going to lay everything about access modifiers in java on the table. Dissect them with examples and make it known to all in a simple way. Let us get started.
A twitter client does what the Twitter site does as well as the Twitter App. The main difference is this: you don’t have to use either of those two to post your random thoughts online and even photos of your drunk friends who will be fired sooner or later. Anyway, so you feel like you have had enough of this conformity stuff and you want to do things your own way – even the forces agree with you, you feel. I will show you how to achieve that! We will use Java programming language to create a simple twitter client that will post our tweets for us. Are you ready?
Towers of Hanoi is a game with three poles labeled A, B and C and several different-size numbered disks, each with a hole in the center. Initially, all of the disks are on pole A, with the largest disk on the bottom, then the next largest and so forth. Here is how it looks when you start the game:
The object of the game is to move all of the disks from pole A to pole B; pole C is used for temporary storage. Here are the rules of the game: