Search Results

Search found 3321 results on 133 pages for 'patterns'.

Page 70/133 | < Previous Page | 66 67 68 69 70 71 72 73 74 75 76 77  | Next Page >

  • Exception handling pattern

    - by treefrog
    It is a common pattern I see where the error codes associated with an exception are stored as Static final ints. when the exception is created to be thrown, it is constructed with one of these codes along with an error message. This results in the method that is going to catch it having to look at the code and then decide on a course of action. The alternative seems to be- declare a class for EVERY exception error case Is there a middle ground ? what is the recommended method ?

    Read the article

  • What's wrong (or right) with this JS Object Pattern?

    - by unsane1
    Here's an example of the pattern I'm using in my javascript objects these days (this example relies on jQuery). http://pastie.org/private/ryn0m1gnjsxdos9onsyxg It works for me reasonably well, but I'm guessing there's something wrong, or at least sub-optimal about it, I'm just curious to get people's opinions. Here's a smaller, inline example of it: sample = function(attach) { // set internal reference to self var self = this; // public variable(s) self.iAmPublic = true; // private variable(s) var debug = false; var host = attach; var pane = { element: false, display: false } // public function(s) self.show = function() { if (!pane.display) { position(); $(pane.element).show('fast'); pane.display = true; } } self.hide = function() { if (pane.display) { $(pane.element).hide('fast'); pane.display = false; } } // private function(s) function init () { // do whatever stuff is needed on instantiation of this object // like perhaps positioning a hidden div pane.element = document.createElement('div'); return self; } function position() { var h = { 'h': $(host).outerHeight(), 'w': $(host).outerWidth(), 'pos': $(host).offset() }; var p = { 'w': $(pane.element).outerWidth() }; $(pane.element).css({ top: h.pos.top + (h.h-1), left: h.pos.left + ((h.w - p.w) / 2) }); } function log () { if (debug) { console.log(arguments); } } // on-instantiation let's set ourselves up return init(); } I'm really curious to get people's thoughts on this.

    Read the article

  • How to dispose the objects created by factory pattern

    - by Ram
    Hi, I am using Factory pattern to create .NET objects of a class. I also need to make sure that all such objects should be disposed before application terminates. Where and How can I dispose the objects created by factory pattern? Shall I dispose in the class in which I am getting the objects created by factory?

    Read the article

  • How should nested components interact with model in a GUI application?

    - by fig-gnuton
    Broad design/architecture question. If you have nested components in a GUI, what's the most common way for those components to interact with data? For example, let's say a component receives a click on one of its buttons to save data. Should the save request be delegated up that component's ancestors, with the uppermost ancestor ultimately passing the request to a controller? Or are models/datastores in a GUI application typically singletons, so that a component at any level of a hierarchy can directly get/set data? Or is a controller injected as a dependency down the hierarchy of components, so that any given component is only one intermediary away from the datastore/model?

    Read the article

  • How to handle request/response propagation up and down a widget hierarchy in a GUI app?

    - by fig-gnuton
    Given a GUI application where widgets can be composed of other widgets: If the user triggers an event resulting in a lower level widget needing data from a model, what's the cleanest way to be able to send that request to a controller (or the datastore itself)? And subsequently get the response back to that widget? Presumably one wouldn't want the controller or datastore to be a singleton directly available to all levels of widgets, or is this an acceptable use of singleton? Or should a top level controller be injected as a dependency through a widget hierarchy, as far down as the lowest level widget that might need that controller? Or a different approach entirely?

    Read the article

  • Refactoring FAT client legacy application

    - by Paul
    I am working on a fat client legacy C++ application which has a lot of business logic mixed in with the presentation side of things. I want to clean things out and refactor the code out completely, so there is a clear seperation of concerns. I am looking at MVC or some other suitable design pattern in order to achieve this. I would like to get recommendations from people who have walked this road before - Do I use MVP or MVC (or another pattern)? What is/are the best practices for undertaking something like this (i.e. useful steps/checks) ?

    Read the article

  • Should Service Depend on Many Repositories, or Break Them Up?

    - by Josh Pollard
    I'm using a repository pattern for my data access. So I basically have a repository per table/class. My UI currently uses service classes to actually get things done, and these service classes wrap, and therefore depend on repositories. In many cases my services are only dependent upon one or two repositories, so things aren't too crazy. Unfortunately, one of my forms in the UI expects the user to enter data that will span five different tables. For this form I made a single service class that depends upon five repositories. Then the methods within the service for saving and loading the data call the appropriate methods on all of the corresponding repositories. As you can imagine, the save and load methods in this service are really big. Also, unit testing this service is getting really difficult because I have to setup so many fake repositories. Would it have been a better choice to break this single service apart into a few smaller services? It would put more code at the UI layer, but would make the services smaller and more testable.

    Read the article

  • Enums and inheritance

    - by devoured elysium
    I will use (again) the following class hierarchy: Event and all the following classes inherit from Event: SportEventType1 SportEventType2 SportEventType3 SportEventType4 I have originally designed the Event class like this: public abstract class Event { public abstract EventType EventType { get; } public DateTime Time { get; protected set; } protected Event(DateTime time) { Time = time; } } with EventType being defined as: public enum EventType { Sport1, Sport2, Sport3, Sport4 } The original idea would be that each SportEventTypeX class would set its correct EventType. Now that I think of it, I think this approach is totally incorrect for two reasons: If I want to later add a new SportEventType class I will have to modify the enum If I later decide to remove one SportEventType that I feel I won't use I'm also in big trouble with the enum. I have a class variable in the Event class that makes, afterall, assumptions about the kind of classes that will inherit from it, which kinda defeats the purpose of inheritance. How would you solve this kind of situation? Define in the Event class an abstract "Description" property, having each child class implement it? Having an Attribute(Annotation in Java!) set its Description variable instead? What would be the pros/cons of having a class variable instead of attribute/annotation in this case? Is there any other more elegant solution out there? Thanks

    Read the article

  • Implementing search functionality with multiple optional parameters against database table.

    - by quarkX
    Hello, I would like to check if there is a preferred design pattern for implementing search functionality with multiple optional parameters against database table where the access to the database should be only via stored procedures. The targeted platform is .Net with SQL 2005, 2008 backend, but I think this is pretty generic problem. For example, we have customer table and we want to provide search functionality to the UI for different parameters, like customer Type, customer State, customer Zip, etc., and all of them are optional and can be selected in any combinations. In other words, the user can search by customerType only or by customerType, customerZIp or any other possible combinations. There are several available design approaches, but all of them have some disadvantages and I would like to ask if there is a preferred design among them or if there is another approach. Generate sql where clause sql statement dynamically in the business tier, based on the search request from the UI, and pass it to a stored procedure as parameter. Something like @Where = ‘where CustomerZip = 111111’ Inside the stored procedure generate dynamic sql statement and execute it with sp_executesql. Disadvantage: dynamic sql, sql injection Implement a stored procedure with multiple input parameters, representing the search fields from the UI, and use the following construction for selecting the records only for the requested fields in the where statement. WHERE (CustomerType = @CustomerType OR @CustomerType is null ) AND (CustomerZip = @CustomerZip OR @CustomerZip is null ) AND ………………………………………… Disadvantage: possible performance issue for the sql. 3.Implement separate stored procedure for each search parameter combinations. Disadvantage: The number of stored procedures will increase rapidly with the increase of the search parameters, repeated code.

    Read the article

  • BlackBerry - Multiple Screens or Single Screen with Content Manager?

    - by Max Gontar
    Hi! I've seen projects which use many screens each one for different layout and functionality. I've seen projects with only one screen (like wizard workflow) where content is changed on user interaction (and this seems to be logical to use single screen in wizards). But also I've seen projects (apps like game or messenger or phone settings utility) which use single screen for different functionalities. I can see such advantages of having single screen in app: keep same decoration design and menu or toolbar (which may be also achieved with inheritance) keep single screen in ui stack (which may be achieved by pop/push screen) easy to handle data over application Can you tell other advantages/disadvantages of single screen app? When its better to use this approach? Thank you!

    Read the article

  • Abstract away a compound identity value for use in business logic?

    - by John K
    While separating business logic and data access logic into two different assemblies, I want to abstract away the concept of identity so that the business logic deals with one consistent identity without having to understand its actual representation in the data source. I've been calling this a compound identity abstraction. Data sources in this project are swappable and various and the business logic shouldn't care which data source is currently in use. The identity is the toughest part because its implementation can change per kind of data source, whereas other fields like name, address, etc are consistently scalar values. What I'm searching for is a good way to abstract the concept of identity, whether it be an existing library, a software pattern or just a solid good idea of some kind is provided. The proposed compound identity value would have to be comparable and usable in the business logic and passed back to the data source to specify records, entities and/or documents to affect, so the data source must be able to parse back out the details of its own compound ids. Data Source Examples: This serves to provide an idea of what I mean by various data sources having different identity implementations. A relational data source might express a piece of content with an integer identifier plus a language specific code. For example. content_id language Other Columns expressing details of content 1 en_us 1 fr_ca The identity of the first record in the above example is: 1 + en_us However when a NoSQL data source is substituted, it might somehow represent each piece of content with a GUID string 936DA01F-9ABD-4d9d-80C7-02AF85C822A8 plus language code of a different standardization, And a third kind of data source might use just a simple scalar value. So on and so forth, you get the idea.

    Read the article

  • C++ setting up "flags"

    - by sub
    Example: enum Flags { A, B, C, D }; class MyClass { std::string data; int foo; // Flags theFlags; (???) } How can I achieve that it is possible to set any number of the "flags" A,B,C and D in the enum above in an instance of MyClass? My goal would be something like this: if ( MyClassInst.IsFlagSet( A ) ) // ... MyClassInst.SetFlag( A ); //... Do I have to use some array or vector? If yes, how? Are enums a good idea in this case?

    Read the article

  • C++ OOP: Which functions to put into the class?

    - by oh boy
    Assume I have a class a: class a { public: void load_data( ); private: void check_data( ); void work_data( ); void analyze_data( ); } Those functions all do something with the class or one of its members. However this function: bool validate_something( myType myData ) { if ( myData.blah > 0 && myData.blah < 100 ) { return true; } return false; } Is related to the class and will only be called by it, so it won't be needed anywhere else Doesn't do anything with the class or its members - just a small "utility" function Where to put validate_something? Inside or outside the class?

    Read the article

  • incapsulation of a code inmatlab

    - by user531225
    my code is pathname=uigetdir; filename=uigetfile('*.txt','choose a file name.'); data=importdata(filename); element= (data.data(:,10)); in_array=element; pattern= [1 3]; locations = cell(1, numel(pattern)); for p = 1:(numel(pattern)) locations{p} = find(in_array == pattern(p)); end idx2 = []; for p = 1:numel(locations{1}) start_value = locations{1}(p); for q = 2:numel(locations) found = true; if (~any((start_value + q - 1) == locations{q})) found = false; break; end end if (found) idx2(end + 1) = locations{1}(p); end end [m2,n2]=size(idx2) res_name= {'one' 'two'}; res=[n n2]; In this code I finding a pattern in one of the column of my data file and counting how many times it's repeated. I have like 200 files that I want to do the same with them but unfotunatlly I'm stuck. this is what I have added so far pathname=uigetdir; files=dir('*.txt'); for k=1:length(files) filename=files(k).name; data(k)=importdata(files(k).name); element{k}=data(1,k).data(:,20); in_array=element;pattern= [1 3]; locations = cell(1, numel(pattern)); for p = 1:(numel(pattern)) locations{p} = find(in_array{k}== pattern(p)); end idx2{k} = []; how can I continue this code..??

    Read the article

  • Whats the best way of using MVC + ajax (jquery) to load page content, aspx or ascx or both

    - by devzero
    I want to have a menu that when I click replaces the content of a "main" div with content from a mvc view. This works just fine if I use a .aspx page, but any master.page content is then doubled (like the and any css/js). If I do the same but uses a .ascx user control the content is loaded without the extras, but if any browser loads the menu item directly (ie search bot's or someone with JS disabled), the page is displayed without the master.page content. The best solution I've found so far is to create the content as a .ascx page, then have a .aspx page load this if it's called directly from the menu link, while the ajax javascript would modify the link to use only the .ascx. This leads to a lot duplication though, as every user control needs it's own .aspx page. I was wondering if there is any better way of doing this? Could for example the master.page hide everything that's not from the .aspx page if it was called with parameter ?ajax=true?

    Read the article

  • In java web application, where should i store users photos?

    - by stunaz
    Hello, this questions may be stupid, but i dont really see how to resolve it : lest say that in my application, i have a user. This user edit his profile, and need to edit his avatar. Where should i store the avatar file? first of all i was saving all the files in src\main\webapp\resources , but each time i redeploy that folder empties. so i dedide to place in an other location : c:\wwwdir\resources, but i can't link local resources from remote pages, so i was not able to display any avatar . any idea? advise? link?

    Read the article

  • A self-creator: What pattern is this? php

    - by user151841
    I have several classes that are basically interfaces to database rows. Since the class assumes that a row already exists ( __construct expects a field value ), there is a public static function that allows creation of the row and returns an instance of the class. Here's a pseudo-code example : class fruit { public $id; public function __construct( $id ) { $this->id = $id; $sql = "SELECT * FROM Fruits WHERE id = $id"; ... $this->arrFieldValues[$field] = $row[$value]; } public function __get( $var ) { return $this->arrFieldValues[$var]; } public function __set( $var, $val ) { $sql = "UPDATE fruits SET $var = $val WHERE id = $this->id"; } public static function create( $id ) { $sql = "INSERT INTO Fruits ( fruit_name ) VALUE ( '$fruit' )"; $id = mysql_insert_id(); $fruit = & new fruit($id); return $fruit; } } $obj1 = fruit::create( "apple" ); $obj2 = & new fruit( 12 ); What is this pattern called? Edit: I changed the example to one that has more database-interface functionality. For most of the time, this kind of class would be instantiated normally, through __construct(). But sometimes when you need to create a new row first, you would call create().

    Read the article

  • What exactly is GRASP's Controller about?

    - by devoured elysium
    What is the idea behind Grasp's Controller pattern? My current interpretation is that sometimes you want to achieve something that needs to use a couple of classes but none of those classes could or has access to the information needed to do it, so you create a new class that does the job, having references to all the needed classes(this is, could be the information expert). Is this a correct view of what Grasp's Controller is about? Generally when googling or SO'ing controller, I just get results about MVC's (and whatnot) which are topics that I don't understand about, so I'd like answers that don't assume I know ASP.NET's MVC or something :( Thanks

    Read the article

  • What Design Pattern To Replace 'CurrentStep' Variable

    - by Rob P.
    Tried to search but didn't know how to phrase it. I've got some code that is essentially... Private CurMajorStep as Integer = 0 Private CurMinorStep as Integer = 0 Public Sub PerformNextStep() Select Case iMajorStep Case 0 ThingOne() Case 1 ThingTwo() Case 2 ThingThree() Case 3 ThingFour() Case 4 AnythingElse() Case 5 Finish() End Select End Sub And then, in some of those, the CurMinorStep keeps track of the current state of that particular 'step'. I hope that all makes sense. The code is messy and I know it's going to be problematic to maintain. Can someone point me to a clean OO pattern to handle this?

    Read the article

  • The right way to implement communication between java objects

    - by imoschak
    I'm working on an academic project which simulates a rather large queuing procedure in java. The core of the simulator rests within one package where there exist 8 classes each one implementing a single concept. Every class in the project follows SRP. These classes encapsulate the behavior of the simulator and inter-connect every other class in the project. The problem that I has arisen is that most of these 8 classes are, as is logical i think, tightly coupled and each one has to have working knowledge of every other class in this package in order to be able to call methods from it when needed. The application needs only one instance of each class so it might be better to create static fields for each class in a new class and use that to make calls -instead of preserving a reference in each class for every other class in the package (which I'm certain that is incorrect)-, but is this considered a correct design solution? or is there a design pattern maybe that better suits my needs?

    Read the article

  • Long list of if statements in Java

    - by steve
    Hi, Sorry I can't find a question answering this, I'm almost certain someone else has raised it before. My problem is that I'm writing some system libraries to run embedded devices. I have commands which can be sent to these devices over radio broadcasts. This can only be done by text. inside the system libraries I have a thread which handles the commands which looks like this if (value.equals("A") { doCommandA() } else if (value.equals"B") { doCommandB() } else if etc. The problem is that there are a lot of commands to it will quickly spiral to something out of control. Horrible to look out, painful to debug and mind boggling to understand in a few months time.

    Read the article

  • How does ruby allow a method and a Class with the same name?

    - by Daniel Beardsley
    I happened to be working on a Singleton class in ruby and just remembered the way it works in factory_girl. They worked it out so you can use both the long way Factory.create(...) and the short way Factory(...) I thought about it and was curious to see how they made the class Factory also behave like a method. They simply used Factory twice like so: def Factory (args) ... end class Factory ... end My Question is: How does ruby accomplish this? and Is there danger in using this seemingly quirky pattern?

    Read the article

< Previous Page | 66 67 68 69 70 71 72 73 74 75 76 77  | Next Page >