Design Patterns web based applications [closed]

A bit decent web application consists of a mix of design patterns. I’ll mention only the most important ones. Model View Controller pattern The core (architectural) design pattern you’d like to use is the Model-View-Controller pattern. The Controller is to be represented by a Servlet which (in)directly creates/uses a specific Model and View based on … Read more

Singletons vs. Application Context in Android?

I very much disagree with Dianne Hackborn’s response. We are bit by bit removing all singletons from our project in favor of lightweight, task scoped objects which can easiliy be re-created when you actually need them. Singletons are a nightmare for testing and, if lazily initialized, will introduce “state indeterminism” with subtle side effects (which … Read more

How to implement the factory method pattern in C++ correctly

First of all, there are cases when object construction is a task complex enough to justify its extraction to another class. I believe this point is incorrect. The complexity doesn’t really matter. The relevance is what does. If an object can be constructed in one step (not like in the builder pattern), the constructor is … Read more

Why is IoC / DI not common in Python?

I don’t actually think that DI/IoC are that uncommon in Python. What is uncommon, however, are DI/IoC frameworks/containers. Think about it: what does a DI container do? It allows you to wire together independent components into a complete application … … at runtime. We have names for “wiring together” and “at runtime”: scripting dynamic So, … Read more

Simplest/cleanest way to implement a singleton in JavaScript

I think the easiest way is to declare a simple object literal: var myInstance = { method1: function () { // … }, method2: function () { // … } }; If you want private members on your singleton instance, you can do something like this: var myInstance = (function() { var privateVar=””; function privateMethod … Read more

How do the Proxy, Decorator, Adapter, and Bridge Patterns differ?

Proxy, Decorator, Adapter, and Bridge are all variations on “wrapping” a class. But their uses are different. Proxy could be used when you want to lazy-instantiate an object, or hide the fact that you’re calling a remote service, or control access to the object. Decorator is also called “Smart Proxy.” This is used when you … Read more

ViewPager and fragments — what’s the right way to store fragment’s state?

When the FragmentPagerAdapter adds a fragment to the FragmentManager, it uses a special tag based on the particular position that the fragment will be placed. FragmentPagerAdapter.getItem(int position) is only called when a fragment for that position does not exist. After rotating, Android will notice that it already created/saved a fragment for this particular position and … Read more

Why create “Implicitly Unwrapped Optionals”, since that implies you know there’s a value?

Before I can describe the use cases for Implicitly Unwrapped Optionals, you should already understand what Optionals and Implicitly Unwrapped Optionals are in Swift. If you do not, I recommend you first read my article on optionals When To Use An Implicitly Unwrapped Optional There are two main reasons that one would create an Implicitly … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)