Search Results

Search found 13727 results on 550 pages for 'oo design'.

Page 60/550 | < Previous Page | 56 57 58 59 60 61 62 63 64 65 66 67  | Next Page >

  • Factory Method Pattern clarification

    - by nettguy
    My understanding of Factory Method Pattern is (Correct me if i am wrong) Factory Method Pattern "Factory Method allow the client to delegates the product creation (Instance Creation) to the subclass". There are two situation in which we can go for creating Factory Method pattern. (i) When the client is restricted to the product (Instance) creation. (ii) There are multiple products available.But a decision to be made which product instance need to be returned. If you want to create Abstract Method pattern You need to have abstract product Concrete Product Factory Method to return the appropriate product. Example : public enum ORMChoice { L2SQL, EFM, LS, Sonic } //Abstract Product public interface IProduct { void ProductTaken(); } //Concrete Product public class LinqtoSql : IProduct { public void ProductTaken() { Console.WriteLine("OR Mapping Taken:LinqtoSql"); } } //concrete product public class Subsonic : IProduct { public void ProductTaken() { Console.WriteLine("OR Mapping Taken:Subsonic"); } } //concrete product public class EntityFramework : IProduct { public void ProductTaken() { Console.WriteLine("OR Mapping Taken:EntityFramework"); } } //concrete product public class LightSpeed : IProduct { public void ProductTaken() { Console.WriteLine("OR Mapping Taken :LightSpeed"); } } public class Creator { //Factory Method public IProduct ReturnORTool(ORMChoice choice) { switch (choice) { case ORMChoice.EFM:return new EntityFramework(); break; case ORMChoice.L2SQL:return new LinqtoSql(); break; case ORMChoice.LS:return new LightSpeed(); break; case ORMChoice.Sonic:return new Subsonic(); break; default: return null; } } } **Client** Button_Click() { Creator c = new Creator(); IProduct p = c.ReturnORTool(ORMChoice.L2SQL); p.ProductTaken(); } Is my understanding of Factory Method is correct?

    Read the article

  • c# Attribute Question

    - by Petoj
    Well i need some help here i don't know how to solve this problem. the function of the attribute is to determine if the function can be run... So what i need is the following: The consumer of the attribute should be able to determine if it can be executed. The owner of the attribute should be able to tell the consumer that now it can/can't be executed (like a event). It must have a simple syntax. This is what i have so far but it only implements point 1, 3. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public class ExecuteMethodAttribute : Attribute { private Func<object, bool> canExecute; public Func<object, bool> CanExecute { get { return canExecute; } } public ExecuteMethodAttribute() { } public ExecuteMethodAttribute(Func<object, bool> canExecute) { this.canExecute = canExecute; } }

    Read the article

  • UML Class Relationships

    - by 01010011
    Hi, I would like to confirm whether I am on the right track when identifying common UML class relationships. For example, is the relationship between: 1 a stackoverflow member and his/her stackoverflow user account categorized as a composition relationship or an aggregation relationship? At first I thought it was an association because this member "has a" account. However on second thought, I am thinking its composition because each "part" (user account) belongs to only one whole (user) at a time, meaning for as long as I am logged into stackoverflow, I have to use this one and only account until I log off. If I log back onto stackoverflow with a different account then its composition again. Do you agree? 2 a database and a person's user account an aggregation relationship? I think so because 1 database (the whole) can store 0...* number of user accounts (the parts) but another database can store the same user accounts. Finally, can anyone recommend a website that specializes in designing code using UML? Thanks in advance

    Read the article

  • Pattern for managing reference count and object life

    - by Gopalakrishnan Subramani
    We have a serial port which is connected to hundreds of physical devices on the same wire. We have protocols like Modbus and Hart to handle the request and response between the application and devices. The question is related to managing the reference count of the channel. When no device is using the channel, the channel should be closed. public class SerialPortChannel { int refCount = 0; public void AddReference() { refCount++; } public void ReleaseReference() { refCount--; if (refCount <= 0) this.ReleasePort(); //This close the serial port } } For each device connected, we create a object for the device like device = new Device(); device.Attach(channel); //this calls channel.AddReference() When the device disconnect, device.Detach(channel); //this calls channel.ReleaseReference() I am not convinced by the reference count model. Are there any better way to handle this problem in .NET World?

    Read the article

  • Concurency problem with Isolation - read-committed

    - by Ratn Deo--Dev
    I have to write a simple demo for amount withdrawl from a joint Bank amount .Andy and Jen holds a joint bank account with number 123 . Suppose they have 100$ in their account .Jen and Andy are operating their account at the same time and both are trying to withdraw 90$ at the time being .My transaction Isolation is set to read-committed and both are able to withdraw money leaving the balance to -(minus)80$ although I have constraint that balance should never be less than 0. I am using hibernate .Is versioning only way to solve this problem or I should go for another Isolation level ?

    Read the article

  • How to avoid injecting dependencies into an object so that it can pass them on?

    - by Pheter
    I am interested in applying dependency injection to my current project, which makes use of the MVC pattern. My controllers will call the models and therefore will need to inject the dependencies into the models. To do this, the controller must have the dependencies (such as a database object) in the first place. The controller doesn't need to make use of some of these dependencies (such as the database object), so I feel that it shouldn't be given this dependency. However, it has to have these dependencies if it is to inject them into the model objects. How can I avoid having dependencies injected into an object just so that it can pass them on? Doing so feels wrong and can result in many dependencies being injected into an object. Edit: I am using PHP.

    Read the article

  • How can i return abstract class from any factory?

    - by programmerist
    using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace EfTestFactory { public abstract class _Company { public abstract List<Personel> GetPersonel(); public abstract List<Prim> GetPrim(); public abstract List<Finans> GetFinans(); } public abstract class _Radyoloji { public abstract List<string> GetRadyoloji(); } public abstract class _Satis { public abstract List<string> GetSatis(); } public abstract class _Muayene { public abstract List<string> GetMuayene(); } public class Company : _Company { public override List<Personel> GetPersonel() { throw new NotImplementedException(); } public override List<Prim> GetPrim() { throw new NotImplementedException(); } public override List<Finans> GetFinans() { throw new NotImplementedException(); } } public class Radyoloji : _Radyoloji { public override List<string> GetRadyoloji() { throw new NotImplementedException(); } } public class Satis : _Satis { public override List<string> GetSatis() { throw new NotImplementedException(); } } public class Muayene : _Muayene { public override List<string> GetMuayene() { throw new NotImplementedException(); } } public class GenoTipController { public object CreateByEnum(DataModelType modeltype) { string enumText = modeltype.ToString(); // will return for example "Company" Type classType = Type.GetType(enumText); // the Type for Company class object t = Activator.CreateInstance(classType); // create an instance of Company class return t; } } public class AntsController { static Dictionary<DataModelType, Func<object>> s_creators = new Dictionary<DataModelType, Func<object>>() { { DataModelType.Radyoloji, () => new _Radyoloji() }, { DataModelType.Company, () => new _Company() }, { DataModelType.Muayene, () => new _Muayene() }, { DataModelType.Satis, () => new _Satis() }, }; public object CreateByEnum(DataModelType modeltype) { return s_creators[modeltype](); } } public class CompanyView { public static List<Personel> GetPersonel() { GenoTipController controller = new GenoTipController(); _Company company = controller.CreateByEnum(DataModelType.Company) as _Company; return company.GetPersonel(); } } public enum DataModelType { Radyoloji, Satis, Muayene, Company } } if i write above codes i see some error: Cannot create an instance of abstract class or interface 'EfTestFactory_Company'How can i solve it? Look please below pic.

    Read the article

  • Hierarchy / Flyweight / Instancing Problem in Python

    - by Dan
    Here is the problem I am trying to solve, (I have simplified the actual problem, but this should give you all the relevant information). I have a hierarchy like so: 1.A 1.B 1.C 2.A 3.D 4.B 5.F (This is hard to illustrate - each number is the parent, each letter is the child). Creating an instance of the 'letter' objects is expensive (IO, database costs, etc), so should only be done once. The hierarchy needs to be easy to navigate. Children in the hierarchy need to have just one parent. Modifying the contents of the letter objects should be possible directly from the objects in the hierarchy. There needs to be a central store containing all of the 'letter' objects (and only those in the hierarchy). 'letter' and 'number' objects need to be possible to create from a constructor (such as Letter(**kwargs) ). It is perfectably acceptable to expect that when a letter changes from the hierarchy, all other letters will respect the same change. Hope this isn't too abstract to illustrate the problem. What would be the best way of solving this? (Then I'll post my solution) Here's an example script: one = Number('one') a = Letter('a') one.addChild(a) two = Number('two') a = Letter('a') two.addChild(a) for child in one: child.method1() for child in two: print '%s' % child.method2()

    Read the article

  • Conventions for the behavior of double or triple "click to select text" features?

    - by John Sullivan
    Almost any mature program that involves text implements "double click to select the word" and, in some cases, "triple click to select additional stuff like an entire line" as a feature. I find these features useful but they are often inconsistent between programs. Example - some programs' double clicks do not select the ending space after a word, but most do. Some recognize the - character as the end of a word, others do not. SO likes to select the entire paragraph as I write this post when I triple click it, VS web developer 2005 has no triple click support, and ultra-edit 32 will select one line upon triple clicking. We could come up with innumerable inconsistencies about how double and triple click pattern matching is implemented across programs. I am concerned about how to implement this behavior in my program if nobody else has achieved a convention about how the pattern matching should work. My question is, does a convention (conventions? maybe an MS or Linux convention?) exist that dictates how these features are supposed to behave to the end user? What, if any, are they?

    Read the article

  • Can a binary tree or tree be always represented in a Database as 1 table and self-referencing?

    - by Jian Lin
    I didn't feel this rule before, but it seems that a binary tree or any tree (each node can have many children but children cannot point back to any parent), then this data structure can be represented as 1 table in a database, with each row having an ID for itself and a parentID that points back to the parent node. That is in fact the classical Employee - Manager diagram: one boss can have many people under him... and each person can have n people under him, etc. This is a tree structure and is represented in database books as a common example as a single table Employee.

    Read the article

  • Is It Incorrect to Make Domain Objects Aware of The Data Access Layer?

    - by Noah Goodrich
    I am currently working on rewriting an application to use Data Mappers that completely abstract the database from the Domain layer. However, I am now wondering which is the better approach to handling relationships between Domain objects: Call the necessary find() method from the related data mapper directly within the domain object Write the relationship logic into the native data mapper (which is what the examples tend to do in PoEAA) and then call the native data mapper function within the domain object. Either it seems to me that in order to preserve the 'Fat Model, Skinny Controller' mantra, the domain objects have to be aware of the data mappers (whether it be their own or that they have access to the other mappers in the system). Additionally it seems that Option 2 unnecessarily complicates the data access layer as it creates table access logic across multiple data mappers instead of confining it to a single data mapper. So, is it incorrect to make the domain objects aware of the related data mappers and to call data mapper functions directly from the domain objects? Update: These are the only two solutions that I can envision to handle the issue of relations between domain objects. Any example showing a better method would be welcome.

    Read the article

  • Passing data structures to different threads

    - by Robb
    I have an application that will be spawning multiple threads. However, I feel there might be an issue with threads accessing data that they shouldn't be. I'm relatively new to threading so bare with me. Here is the structure of the threaded application (sorry for the crudeness): MainThread / \ / \ / \ Thread A Thread B / \ / \ / \ / \ / \ / \ Thread A_1 Thread A_2 Thread B_1 Thread B_2 Under each lettered thread (which could be many), there will only be two threads and they are fired of sequentially. The issue i'm having is I'm not entirely sure how to pass in a datastructure into these threads. So, the datastructure is created in MainThread, will be modified in the lettered thread (Thread A, etc) specific to that thread and then a member variable from that datastructure is sent to Letter_Numbered threads. Currently, the lettered thread class has a member variable and when the class is constructed, the datastructure from mainthread is passed in by reference, invoking the copy constructor so the lettered thread has it's own copy to play with. The lettered_numbered thread simply takes in a string variable from the data structure within the lettered thread. My question is, is this accceptable? Is there a much better way to ensure each lettered thread gets its own data structure to play with? Sorry for the somewhat poor explanation, please leave comments and i'll try to clarify.

    Read the article

  • Simply doing modelType.ToString() isn't sufficient, How can i use it via Activator.CreateInstance?

    - by programmerist
    public class MyController { public object CreateByEnum(DataModelType modeltype) { string enumText = modeltype.ToString(); // will return for example "Company" Type classType = Type.GetType(enumText); // the Type for Company class object t = Activator.CreateInstance(classType); // create an instance of Company class return t; } } public class CompanyView { public static List<Personel> GetPersonel() { MyController controller = new MyController(); _Company company = controller.CreateByEnum(DataModelType.Company) as _Company; return company.GetPersonel(); } } public enum DataModelType { xyz, klm, tucyz, Company } Yes, I agree Activator.CreateInstance() is very useful. Unfortunately, I need to pass in the correct type. That means building the correct string to pass to Type.GetType(). If I trace through the call to Controller.CreatebyEnum() in the code I posted above, simply doing modelType.ToString() isn't sufficient, even for the case of DataModelType.Company. My solution'll be maintenance bottleneck. What would be better is something that takes the results of modelType.ToString() and then recursively searches through all the types found in all the assemblies loaded in the current AppDomain. According to MSDN, Type.GetType() only searches the current calling assembly, and mscorlib.dll. How can i do that? . i need best performance?

    Read the article

  • Some basic UML questions

    - by devoured elysium
    What does it mean when you have something as the following picture? Each Customer has none, one or more Orders while each Order has only one Customer? And in relationship to the following one: What does the black diamond mean in this context? How is that black diamond called? Thanks

    Read the article

  • Is it good to subclass a class only to separate some functional parts?

    - by prostynick
    Suppose we have abstract class A (all examples in C#) public abstract class A { private Foo foo; public A() { } public void DoSomethingUsingFoo() { //stuff } public void DoSomethingElseUsingFoo() { //stuff } //a lot of other stuff... } But we are able to split it into two classes A and B: public abstract class A { public A() { } //a lot of stuff... } public abstract class B : A { private Foo foo; public B() : base() { } public void DoSomethingUsingFoo() { //stuff } public void DoSomethingElseUsingFoo() { //stuff } //nothing else or just some overrides of A stuff } That's good, but we are 99.99% sure, that no one will ever subclass A, because functionality in B is very important. Is it still good to have two separate classes only to split some code into two parts and to separate functional elements?

    Read the article

  • Facade controller, is it efficient?

    - by Berlioz
    Using a facade controller pattern in .net. It seems as if though it is not efficient BECAUSE, for every event that happens in a domain object(Sales, Register, Schedule, Car) it has to be subscribed to by the controller(use case controller) and then the controller in turn has to duplicate that same event to make it available for the presentation, so that the presentation can show it to the user. Does this make sense? Please comment!

    Read the article

  • date representation in user interface

    - by Samuel
    Most of the sites capture the date (e.g. birth date) information as either a single entity (i.e via a calendar control) or instead as separate fields (date, month, year). Are there any benefits in showing them as separate fields? Are they represented in the database as DATE data type or as separate fields. I am just trying to understand the pros & cons of representing the date field.

    Read the article

  • Grasp Controller, Does it really need a UI to exist?

    - by dbones
    I have a Domain model which can be in multiple states, and if these states go out of a given range it the domain should automatically react. For example I have a Car which is made of multiple things which have measurements the Engine - Rev counter and Temperature the Fuel Tank - capacity Is is plaseable to have a CarStateController, which observses the engine and the tank, and if these states go out of range IE the engine temperature goes above range, turn the engine fan on?? There is no UI, (you could argue it would show a light on the dash board, but for this case it does not) is this a valid use of a GRASP controller pattern? if not what is this CarStateController Called? Or have I completely missed the point and this should be the State Pattern?

    Read the article

  • Designing a class in such a way that it doesn't become a "God object"

    - by devoured elysium
    I'm designing an application that will allow me to draw some functions on a graphic. Each function will be drawn from a set of points that I will pass to this graphic class. There are different kinds of points, all inheriting from a MyPoint class. For some kind of points it will be just printing them on the screen as they are, others can be ignored, others added, so there is some kind of logic associated to them that can get complex. How to actually draw the graphic is not the main issue here. What bothers me is how to make the code logic such that this GraphicMaker class doesn't become the so called God-Object. It would be easy to make something like this: class GraphicMaker { ArrayList<Point> points = new ArrayList<Point>(); public void AddPoint(Point point) { points.add(point); } public void DoDrawing() { foreach (Point point in points) { if (point is PointA) { //some logic here else if (point is PointXYZ) { //...etc } } } } How would you do something like this? I have a feeling the correct way would be to put the drawing logic on each Point object (so each child class from Point would know how to draw itself) but two problems arise: There will be kinds of points that need to know all the other points that exist in the GraphicObject class to know how to draw themselves. I can make a lot of the methods/properties from the Graphic class public, so that all the points have a reference to the Graphic class and can make all their logic as they want, but isn't that a big price to pay for not wanting to have a God class?

    Read the article

< Previous Page | 56 57 58 59 60 61 62 63 64 65 66 67  | Next Page >