Design patterns Sharding (sic!) the web tier in order to prevent a load balancer bottleneck?

How do large web sites which cannot be completely stateless achieve extreme scalability at the web tier? There are sites like eBay and Amazon, which cannot be completely stateless, as they have a shopping cart or something like that. It isn't feasible to encode every item in the shopping cart into the URL, nor is it feasible to encode every item into a cookie and send it at every connection. So Amazon simply stores the session-id into the cookie which is being sent. So I understand that the sca

Design patterns Implementing state-driven classes

Assume a requirement of implementing a class "CAR". Now, this class contains various states like "un-ignited", "ignited", "broken-down", "punctured", etc., The way I look at to implement this requirement is to have boolean flags aka "properties" in the class and 'check the state' using these boolean flags inside each member function. For example, CAR.goRacing() { if(bIsPunctured) return ENUM_CANT_DRIVE; //Start the Engine... } This implementation, trivial so it might look,

Design patterns design pattern for related inputs

My question is a design question : let's say i have a data entry web page with 4 drop down lists, each depending on the previous one, and a bunch of text boxes. ddlCountry (DropDownList) ddlState (DropDownList) ddlCity (DropDownList) ddlBoro (DropDownList) txtAddress (TxtBox) txtZipcode(TxtBox) and an object that represents a datarow with a value for each: countrySeqid stateSeqid citySeqid boroSeqid address zipCode naturally the country, state, city and boro values will be values of prim

Design-patterns for memcache-client-like connection management?

I need to manage connections to a number of services, hosted across a number of servers. Each service is available on more than one server for redundancy. What I'd like to do is build a client, similar to memcached or beanstalkd clients, that can connect to the services in a round-robin fashion; if a connection goes down it tries the next one until it has gone through the list N times and no servers are responding. What (design) patterns should I be researching to implement this? The method o

Design patterns Model Profiles as Pattern Instances

Suppose you have a profile for an application. This profile stores some data specifically about one user. You can persist the details of the profile and pull them back each run. Does a profile make a good candidate for the State pattern? If not, is there a good heuristic to model this sort of functionality?

Design patterns Is it a good practice to catch all exceptions and re-throw them as a particular type of exception in terms of classification?

Is it a good practice to catch all exceptions and re-throw them as a specific type -basically to classify all the exceptions thrown from a particular part (or service) of an application? Something like: // This class is used to label all the exceptions occured on // Race Cars Service calls as RaceCarsServiceException public class RaceCarsServiceException : Exception { public class RaceCarsServiceException (Exception e) : base("Something went wrong!", e) { // Basicall

Design patterns WCF and the Domain Model - doesnt it need to be Anemic?

Here is the argument against an Anemic Domain Model as presented by Martin Fowler (read link). Now based on this description, one would expect the business object to not just have getters and setters, but also behavior, such as what I show below. public class Student { private List<Course>_courses = new List<Course>(); public string Name{get; set;} public ReadOnlyCollection<Course> Courses { get{ return _courses.AsReadOnly();} } public void Add

Design patterns composite pattern design questions

I have a question about two operations you commonly see in an example Composite class diagram. * GetDescendents * GetChild(int) A common example being Files and Directories, I'll stick with that. Let's say the operation of interest is Size, so File has a real size and Directory has a Size derived from the recursive iteration of GetDescendents. So far so good. My question has to do with the client's use of GetDescendents. Say you need the files in a directory that are images for some given oper

Design patterns best practice/design pattern for language files

I'm looking for a good way to have multiple translations in an application. Right now I'm using a class that reads the terms from an ini file. Every term is a variable. For example: string allowed ; [...] allowed = config.readString (sectionName, "allowed") ; the good of this solution is that it's light, easy to implement and checked at compile time but it's not flexible enough. a more flexible solution could be to use an associative array (or similar) currLang [ "allowed" ] Does any-on

Design patterns In MVP should my presenter provide views to its view?

I'm just learning how to use MVP and I want to make sure that I'm "doing it right". I have main view with an associated presenter. This main view is composed of a few sub-components, at least one of which can be interchanged. So I turned these sub-components into their own view/presenter pairs. The way I currently have my project setup is that main view/presenter launches off the project. When the main presenter is instantiated it makes calls to factory functions that create the other view/pre

Design patterns Which software design patterns do common GUI frameworks exhibit?

I have been a python programmer 7+ years now, and been designing with PyQt for 3+ years... But I am not a classically trained Comp Sci. major. More recently I have been learning Go and been actively following the Golang-nuts discussion list which is filled with extremely intelligent developers. From this discussion group, I have seen many references to software design patterns, such as Observer, Reactor, etc. Again because I am not a CS major, I never really learned all of this terminology and t

Design patterns Design patterns when no UI is needed

I'm familiar with the basics and concepts of a few design patterns (namely MVC, PM and the similar MVVM). Both of these (IMO) require a UI. My project is pretty much run using Windows Services (a service runs, does something and updates a database - a SQL Agent Job runs and depending on the 'state' of a column in the table will then move it around/act upon it etc, another windows service is checking the table for another state which takes it out of the database and save it on the hard drive). O

Design patterns Design help: Hashmap in testng dataprovider

I been writing Test scripts using TestNG's DataProvider feature. Till now I was happy with the way I was doing it as the number of parameters I was passing was less than 10, but some of the new pages I am testing have more than 30-35 parameters, adding these parameters to the Test Method makes it look really ugly so I started using the varArgs 'Object...'. Its a good way of dynamically passing parameters, but then using them is difficult as you have to be really careful with the indexes and pr

Design patterns proxy design pattern using reflection

I came across the code given below from the following link: I am failing to understand the following piece of code: Animal proxy = (Animal) Proxy.newProxyInstance(realSubject.getClass() .getClassLoader(), realSubject.getClass().getInterfaces(), new AnimalInvocationHandler(realSubject)); Can someone please provide some resource/pointer to help me understand, as i have not done any work on reflection. import java.lang.reflect.Proxy;

Design patterns Is this a strategy pattern or command pattern?

I'm developing a calculator application for a university project. I've encapsulated each calculator operation such as add, multiply, square, etc in separate classes which all have a common superclass. Is this an example of the command or strategy pattern, they seem to be quite similar and I can't decide here. Thanks.

Design patterns What is the difference between the read-only interface pattern and the facade pattern?

Say I write a facade for a class and expose all it's methods except for it's setters. What is the functional difference with the read-only interface pattern? Based on the wikipedia article on immutable interfaces I'd say the facade has the advantages of the immutable interface (when I name my class Foo and my facade is ImmutableFoo) while not having the disadvantage of being able to cast the immutable interface "to their concrete, mutable type, and have their state mutated". EDIT As it turns

Design patterns DAO calling another DAO for nested objects

I'll explain it with an example. Assume, I've two tables: Department(deptId, deptName) Employee(empId, empName, deptId) And a DAO for each of them. Employee has Many to One relationship to Department. In my domain model Employee refers Department object. Now when I call finder on EmployeeDAO, should I make a call to DepartmentDAO from inside EmployeeDAO, to return a completely formed Employee Object(with Department). Below post suggests against it: Can a DAO call DAO? Note : Domain ob

Design patterns What Design pattern for list of choices , when user select choice

I have an application where the user selects Initial choice and this choice will present another set of choices, each choice can invoke the flow of the application of present another list of choices. For example: app: what is you name ? user: poko app: what is your profession? 1.programmer 2.Lawyer 3.blacksmith user: 2 app: what total income per year 1. above 100$ 2. above 200$ user: 2 in the application: app invokes layer handler with handling income above 200 $ What will b

Design patterns Adapter Design Pattern: Expose private adaptee instance of the Adapter class Except for the Client code?

Is there any way I could have private adaptee instance inside the Adapter class exposed when I need it except for the client code? To elaborate, there are certain cases where I would want to expose the adaptee instance from the Adaptor for the public, but I do Not want to do it with the client code. Therefore would it be appropriate to write a method within the Adapter class like this one: public Adaptee ExposeAdaptee(){ return _adapteeInstance; }

Design patterns How to use variable names without overriding a module name?

math.random() works out of the box, but if I set math to something else it breaks local math = 1 + 1 -- set math to something else math.random() -- breaks is there any way to make math.random() still work while setting local math = 1 + 1? I have a bunch of modules with dot-notation functions such as coord.get() or offset.get() but then those base words like coord and offset become unusable for variable names, which is annoying

Design patterns Should I use a site builder to create my companys page or code it

I am a full stack developer of over 10 years. Very experienced with React, Angular, Amazon Hosting ect. though I haven't touched sites like wordpress or squarespace. I need to create a website to promote my event production company and it's events while also providing visitors with more and more ability to sign up, apply to volunteer, and maybe eventually become a portal for my staff and promoters. Would coding such a simple site out be overkill and create too much work development work for my E

Design patterns Communicate between View Models in MVVM

I am using MVVM pattern in my project. Here is the pseudo code. class ViewModelA { propertyA; methodA(); // updates propertyA } class ViewModelB { methodB() { // update properties of ViewModelB // Needs to update propertyA of ViewModelA } } I have two view models ViewModelA and ViewModelB. MethodB of ViewModelB needs to update propertyA of ViewModelA. I can keep a reference of an instance of ViewModelA inside ViewModelB and call methodA to update propertyA of V

Design patterns How to efficiently update the state of an application after the user corrects false data about past events?

Suppose I'm making a voice-controlled application where spoken utterances will occasionally be misrecognized. I want the user to be able to occasionally correct misrecognized utterances and have the state of application, including the state of the GUI, correct itself as efficiently as possible. Are there existing software frameworks or design patterns that would simplify this? I've looked into self-adjusting computation, but it doesn't seem to be geared towards data that streams in constantly.

Design patterns Mobile apps support - All the server version

I have a mobile-app in stores and my customers have server(web apps + API) in their end. When they are using the app, the user has to enter their server name and login. My customer have different version(web apps+API) of servers. They will use the common mobile app and does support all the kind of version as of now But We are trying to implement the new features/bug fixing in the mobile app. While we are releasing the app in store, all the user gets the latest one but some of users unable to

Design patterns How should a "Bridge" design pattern be implemented for more than two hierarchies?

This explains the "Bridge" pattern I'm referring to: Here's a scenario from the post above: Say you have a geometric Shape class with a pair of subclasses: Circle and Square. You want to extend this class hierarchy to incorporate colors, so you plan to create Red and Blue shape subclasses. However, since you already have two subclasses, you’ll need to create four class combinations such as BlueCircle and RedSquare. The problem this scen

Design patterns Observer Design Pattern vs "Listeners"

It seems to me that the Observer design pattern as described in GOF is really the same thing as Listeners found in various toolkits. Is there a difference between the concepts, or are Listeners and Observers really the same thing. (I'm not looking for any specific computer language implementation, I just want to understand the difference (if any) from a design point of view. Yes, I know there are several answers to similar questions on SOF, but they're rooted in specific questions about specif

Design patterns Name for factoring out repeated code into separate function

I'm trying to find research/advice on a particular code refactoring pattern, but I'm finding it hard to locate, since I'm not sure whether there's a good name for it. It's very similar to factoring out repeated code, except the code wasn't repeated in the first place: it was just stashed away in a conditional branch of a larger function, accessible via a parameter of that function. In pseudocode, the before: function frobnicate(id, check_only = false) { if id cannot be frobnicated

Design patterns Using Adapters with a Facade

My architecture previously was using a facade to perform a number of tasks through a simple set of methods. Something like: startComputer(...) shutdownComputer(...) As I expand the application, I have the need to translate multiple types of input to the facade itself. Let's say that in the past startComputer took 6 parameters, and in the new architecture it takes some sort of parseable string input, and in another case, some base-64 encoded mess. Basically, across the board, I want to access

Design patterns How to design using patterns

I am a college student and I'm learning about software patterns (specifically the ones mentioned in the GoF book). I have never been that good at software design, but I'm learning how each pattern works and solves different problems to produce more flexible software. I have a question that has been bugging me. What's the best way to look at a problem (a piece of software that needs to be written) and determine how to organize it and apply patterns? I recently had a group Java project that went

Design patterns Alternative to instanceof?

I've heard that it is bad design to use instanceof or equivalent (, when should we use instanceof and when not) which I can agree on, mainly because it can make the code hard to reuse. However, in some cases I've found it hard to come up with a good alternative to instanceof. For example, say that I want to make a Real-Time-Strategy game. The game consists of obstacles, buildings and tanks, all placed on a grid and each entitity takes up e

Design patterns How do you expose events wrapped by a Facade class?

Consider the following structure: Class A: Method A - Fires Event A Class B: Method B - Fires Event B Class C: Method C - Fires Event C Facade: Method ABC (calls method A, B and C), Fires Event A, B and C. How do you expose events A, B and C? Do you bubble up the event from A, B and C? Do you create another event? Do you expose classes A, B and C and let the client code subscribe to the event?

Design patterns Suggest a pattern or architecture for software license registration and validation mechanism

I'm working on building a generic and reusable software license registration library that will be embedded into multiple products. I'm thinking of writing an Enterprise Library for this, and would like to get some better suggestions here. The mechanism will be some sort of plugin which will drive the registration mechanism of the product in which it is implemented. The product will generate it's GUI for the registration form, but the business logic for license generation and validation will be

Design patterns observer pattern - singular data point vs. large set

I'm trying to get my head around observer pattern, and conceptually - I get it, it seems REALLY beneficial for lots of stuff... however... in all the examples and reading I'm doing - it seems all the examples use a "single" data point, and a single class to manage that data point, so of course if 'x' changes, notify some other (registered) class... what does one do when there are multiple methods in a class that MAY change multiple data points? - are the "observers" supposed to register for a

Design patterns Where to put abstractions in SOLID programming?

I develop a game engine in XNA. This engine has some modules (subprojects), such as Renderer, StateManagement, etc. Refering to Dependency Inversion Principle: "High-level modules should not depend on low-level modules. Both should depend on abstractions." My question is: Where should I put those abstractions in practice? Should I create some projects with groups of corresponding abstractions, or create one project with all the abstractions of my engine? The first solution will mess up my proje

Design patterns "Double polymorphism" : double dispatch pattern, or just visitor pattern?

I have a class BC_TOYFD { public: BC_TOYFD( BS_TOYFD * pBS, BC2 dBC2 ); virtual ~BC_TOYFD( void ) ; BS_TOYFD * _pBS ; BC2 _dBC2 ; double _PDA ; // store price down approximation double _PUA ; // store price up approximation virtual void COMPUTEBVDOWNFOR( PAYOFF_TOYFD * pPAYOFF, double * attime ) = 0 ; virtual void COMPUTEBVUPFOR( PAYOFF_TOYFD * pPAYOFF, double * attime ) = 0 ; }; from which derives a class DIRICHLET_TOYF

Design patterns DDD Auditing? Domain Layer or Repository Layer?

The application i'm currently working on requires every made to the database be audited in another table: ex: Employee Table has EmployeeAuditTable I've been debating on where i should put the auditing functionality! Following DDD could anyone offer me their advice and opinion. The options that come to mind to me are the following 1.) When a "Repository" calls save changes, i should perform the auditing logic from the repository ( Is this bad design/practice to have the Repository not only p

Design patterns Identifying a pattern

While I was designing an Android application I've created some classes related between them. I am sure this kind of pattern/relationship is popular and I would like to know more about it for properly naming the classes and learn more about the pattern (to improve the design) I have a class, Book, with some basic attributes: title, author and synopses. The books are stored in files, one file per book, and there is a class that manage the file operations load/save/delete. I've called this cla

Design patterns What is the name and explanation of the two-step object construction-initialization pattern?

Is there an in-depth article explaining it? I want to be aware of available solutions and to avoid re-inventing patterns. The idea is that an instance is useful even without being completely initialized and the initialization dependencies are not known at construction time. So the instance construction is a two step process: first create via a normal constructor, then initialize via a public method at some (possibly much later) stage. Here is a sample: public static void Main() { var muta

Design patterns How to choose a design pattern when your customer' requirements are still a bit hazy

I have a flat file containing person "Records" which I get from a service provider. Each Record is in fact a list of Records. Each line in the file represents a Record with a given Type. A person Record always contains the types '001' and '099', representing a start- and an end Record fora person. Other records are added to a person entry based on an 'incident'. Hence a Record is built based on the given incident. Example. 000 # Start of doc. 001 # Person begin. ... n Records (n > 001 &am

Design patterns Is there a better design pattern for this requirement?

I'm dealing with a design pattern problem: In a library system, admin can grant the certain permission of user information management (e.g., creating or searching user info) to other departments or schools. So I tried to use the visitor pattern. Users like teachers and students are the subclass of User and the admin or other department is the visitor. However, more user types can be added is also the requirement. It is not suitable to add more elements in the visitor pattern. What design patter

Design patterns How to model protobuf proto file

My application has various clients (say for example Client1, Client 2, Client3 ....and so on). Clients share some generic properties and has some unique data. In my .proto file I want to model this kind of behavior. I came up with : message MyClientsData { BaseClientData baseData; Client1SpecificData client1; Client2SpecificData client2; ... and so forth... } BaseClientData is the common data across all clients. This works for simple use case when number of clients are very limited,

  1    2   3   4   5   6  ... 下一页 最后一页 共 19 页