Search Results

Search found 150 results on 6 pages for 'elysium'.

Page 5/6 | < Previous Page | 1 2 3 4 5 6  | Next Page >

  • Using enums or a set of classes when I know I have a finite set of different options?

    - by devoured elysium
    Let's say I have defined the following class: public abstract class Event { public DateTime Time { get; protected set; } protected Event(DateTime time) { Time = time; } } What would you prefer between this: public class AsleepEvent : Event { public AsleepEvent(DateTime time) : base(time) { } } public class AwakeEvent : Event { public AwakeEvent(DateTime time) : base(time) { } } and this: public enum StateEventType { NowAwake, NowAsleep } public class StateEvent : Event { protected StateEventType stateType; public MealEvent(DateTime time, StateEventType stateType) : base(time) { stateType = stateType; } } and why? I am generally more inclined to the first option, but I can't explain why. Is it totally the same or are any advantages in using one instead of the other? Maybe with the first method its easier to add more "states", altough in this case I am 100% sure I will only want two states: now awake, and now asleep (they signal the moments when one awakes and one falls asleep).

    Read the article

  • When to define SDD operations System->Actor?

    - by devoured elysium
    I am having some trouble understanding how to make SDDs, as I don't fully grasp why in some cases one should define operations for System - Actor and in others don't. Here is an example: 1) The User tells the System that wants to buy some tickets, stating his client number. 2) The System confirms that the given client number is valid. 3) The User tells the System the movie that wants to see. 4) The System shows the set of available sessions and seats for that movie. 5) The System asks the user which session/seat he wants. 6) The user tells the System the chosen session/seat. This would be converted to: a) -----> tellClientNumber(clientNumber) b) <----- validClientNumber c) -----> tellMovieToSee(movie) d) <----- showsAvailableSeatsHours e) -----> tellSystemChosenSessionSeat(session, seat) I know that when we are dealing with SDD's we are still far away from coding. But I can't help trying to imagine how it how it would have been had I to convert it right away to code: I can understand 1) and 2). It's like if it was a C#/Java method with the following signature: boolean tellClientNumber(clientNumber) so I put both on the SDD. Then, we have the pair 3) 4). I can imagine that as something as: SomeDataStructureThatHoldsAvailableSessionsSeats tellSystemMovieToSee(movie) Now, the problem: From what I've come to understand, my lecturer says that we shouldn't make an operation on the SDD for 5) as we should only show operations from the Actor to the System and when the System is either presenting us data (as in c)) or validating sent data (such as in b)). I find this odd, as if I try to imagine this like a DOS app where you have to put your input sequencially, it makes sense to make an arrow even for 5). Why is this wrong? How should I try to visualize this? Thanks

    Read the article

  • Visual Studio 2010 and Test Driven Development

    - by devoured elysium
    I'm making my first steps in Test Driven Development with Visual Studio. I have some questions regarding how to implement generic classes with VS 2010. First, let's say I want to implement my own version of an ArrayList. I start by creating the following test (I'm using in this case MSTest): [TestMethod] public void Add_10_Items_Remove_10_Items_Check_Size_Is_Zero() { var myArrayList = new MyArrayList<int>(); for (int i = 0; i < 10; ++i) { myArrayList.Add(i); } for (int i = 0; i < 10; ++i) { myArrayList.RemoveAt(0); } int expected = 0; int actual = myArrayList.Size; Assert.AreEqual(expected, actual); } I'm using VS 2010 ability to hit ctrl + . and have it implement classes/methods on the go. I have been getting some trouble when implementing generic classes. For example, when I define an .Add(10) method, VS doesn't know if I intend a generic method(as the class is generic) or an Add(int number) method. Is there any way to differentiate this? The same can happen with return types. Let's assume I'm implementing a MyStack stack and I want to test if after I push and element and pop it, the stack is still empty. We all know pop should return something, but usually, the code of this test shouldn't care for it. Visual Studio would then think that pop is a void method, which in fact is not what one would want. How to deal with this? For each method, should I start by making tests that are "very specific" such as is obvious the method should return something so I don't get this kind of ambiguity? Even if not using the result, should I have something like int popValue = myStack.Pop() ? How should I do tests to generic classes? Only test with one generic kind of type? I have been using ints, as they are easy to use, but should I also test with different kinds of objects? How do you usually approach this? I see there is a popular tool called TestDriven for .NET. With VS 2010 release, is it still useful, or a lot of its features are now part of VS 2010, rendering it kinda useless? Thanks

    Read the article

  • Designing a chain of states

    - by devoured elysium
    I want to model a kind of FSM(Finite State Machine). I have a sequence of states (let's say, from StateA to StateZ). This sequence is called a Chain and is implemented internally as a List. I will add states by the order I want them to run. My purpose is to be able to make a sequence of actions in my computer (for example, mouse clicks). (I know this has been done a zillion times). So a state is defined as a: boolean Precondition() <- Checks to see if for this state, some condition is true. For example, if I want to click in the Record button of a program, in this method I would check if the program's process is running or not. If it is, go to the next state in the chain list, otherwise, go to what was defined as the fail state (generally is the first state of them all). IState GetNextState() <- Returns the next state to evaluate. If Precondition() was sucessful, it should yield the next state in the chain otherwise it should yield the fail state. Run() Simply checks the Precondition() and sets the internal data so GetNextState() works as expected. So, a naive approach to this would be something like this: Chain chain = new Chain(); //chain.AddState(new State(Precondition, FailState, NextState) <- Method structure chain.AddState(new State(new WinampIsOpenCondition(), null, new <problem here, I want to referr to a state that still wasn't defined!>); The big problem is that I want to make a reference to a State that at this point still wasn't defined. I could circumvent the problem by using strings when refrering to states and using an internal hashtable, but isn't there a clearer alternative? I could just pass only the pre-condition and failure states in the constructor, having the chain just before execution put in each state the correct next state in a public property but that seems kind of awkward.

    Read the article

  • class modifier issues in C# with "private" classes

    - by devoured elysium
    I had a class that had lots of methods: public class MyClass { public bool checkConditions() { return checkCondition1() && checkCondition2() && checkCondition3(); } ...conditions methods public void DoProcess() { FirstPartOfProcess(); SecondPartOfProcess(); ThirdPartOfProcess(); } ...process methods } I identified two "vital" work areas, and decided to extract those methods to classes of its own: public class MyClass { private readonly MyClassConditions _conditions = new ...; private readonly MyClassProcessExecution = new ...; public bool checkConditions() { return _conditions.checkConditions(); } public void DoProcess() { _process.DoProcess(); } } In Java, I'd define MyClassConditions and MyClassProcessExecution as package protected, but I can't do that in C#. How would you go about doing this in C#? Setting both classes as inner classes of MyClass? I have 2 options: I either define them inside MyClass, having everything in the same file, which looks confusing and ugly, or I can define MyClass as a partial class, having one file for MyClass, other for MyClassConditions and other for MyClassProcessExecution. Defining them as internal? I don't really like that much of the internal modifier, as I don't find these classes add any value at all for the rest of my program/assembly, and I'd like to hide them if possible. It's not like they're gonna be useful/reusable in any other part of the program. Keep them as public? I can't see why, but I've let this option here. Any other? Name it! Thanks

    Read the article

  • Which kind of method signature do you prefer and why?

    - by devoured elysium
    Ok, this is probably highly subjective but here it comes: Let's assume I'm writing a method that will take a printscreen of some region of the screen. Which method signature would you prefer and why? Bitmap DoPrintScreen(int x, int y, int width, int height); Bitmap DoPrintScreen(Rectangle rect); Bitmap DoPrintScreen(Point point, Size size); Other Why? I keep seeing myself repeatedly implementing both 1) and 2) (redirecting one of them to the other) but I end up usually just using one of them, so there really is no point in having both. I can't decide which would be better. Maybe I should use the signature that looks the most with the method I'll be calling to make the printscreen?

    Read the article

  • Should I put actors in the Domain-Model/Class-Diagram?

    - by devoured elysium
    When designing both the domain-model and class-diagrams I am having some trouble understanding what to put in them. I'll give an example of what I mean: I am doing a vacations scheduler program, that has an Administrator and End-Users. The Administrator does a couple of things like registering End-Users in the program, changing their previleges, etc. The End-User can choose his vacations days, etc. I initially defined an Administrator and End-User as concepts in the domain-model, and later as classes in the class-diagram. In the class-diagram, both classes ended up having a couple of methods like Administrator.RegisterNewUser(); Administrator.UnregisterUser(int id); etc. Only after some time I realised that actually both Administrator and End-User are actors, and maybe I got this design totally wrong. Instead of filling Administrator and End-User classes with methods to do what my Use-Cases request, I could define other classes from the domain to do them, and have controllers handle the Use-Cases(actually, I decided to do one for each Use-Case). I could have a UserDatabase.RegisterNewUser() and UserDatabase.UnregisterUser(int id);, for example, instead of having those methods on the Administrator class. The idea would be to try to think of the whole vacation-scheduler as a "closed-program" that has a set of features and doesn't bother with things such as authentication, that should be internal/protected, being that the only public things I'd let the outside world see would be its controllers. Is this the right approach? Or am I getting this totally wrong? Is it generally bad idea to put Actors in the domain-model/class-diagrams? What are good rules of thumb for this? My lecturer is following Applying UML and Patterns, which I find awful, so I'd like to know where I could look up more info on this described actor-models situation. I'm still a bit confused about all of this, as this new approach is radically different from anything I've done before.

    Read the article

  • Problem when trying to define Show for my Point3D type in Haskell

    - by devoured elysium
    I am trying to define Show for my Point3D type: type Point3D = (Integer, Integer, Integer) instance Show Point3D where show (x,y,z) = "<" ++ (show x) ++ "," ++ (show y) ++ "," ++ (show z) ++ ">" yet I must be missing something in the sintax, as I am always getting an error: Illegal instance declaration for `Show Point3D' (All instance types must be of the form (T t1 ... tn) where T is not a synonym. Use -XTypeSynonymInstances if you want to disable this.) In the instance declaration for `Show Point3D' What am I doing wrong?

    Read the article

  • Adding behaviour to a set of classes

    - by devoured elysium
    I have defined an Event class: Event and all the following classes inherit from Event: SportEventType1 SportEventType2 SportEventType3 SportEventType4 Right now I will only have SportEvents but I don't know if in the future I'll want some other kind of events that doesn't even have anything to do with Sports. Later, I will want to draw some graphics with info taken from Events, and the drawing logic can be a bit complex. But, for the moment, I think I shouldn't think of how the drawing will be done and I believe that maybe it'd be better if that drawing part was not put as an integral part of the Event/SportEventX class chain. I am looking for solutions for this problem. I know I could just make Event have an instance variable(attribute, for the java crowds) pointing to something as an IDrawInterface, but that would make the Event class "assume" it will be later used for drawing. I would like to make the Event class oblivious to this if possible. Thanks!

    Read the article

  • Help choosing the right data structure

    - by devoured elysium
    I need a data structure with the following requirements: Needs to be able to get elements by index (like a List). I will always just add / remove elements from the end of the structure. I am inclined to use an ArrayList. In this situation, it seems to be O(1) both to read elements (they always are?), remove elements (I only need to remove them at the end of the list) and to add(I only add to the end of the list). There is only the problem that time to time the ArrayList will have a performance penalty when it's completly full and I need to add more elements to it. Is there any other better idea? I don't think of a data structure that'd beat the ArrayList here. Thanks

    Read the article

  • When to define SDD(System Sequence Diagram) operations System->Actor?

    - by devoured elysium
    I am having some trouble understanding how to make System Sequence Diagrams, as I don't fully grasp why in some cases one should define operations for System - Actor and in others don't. Here is an example: Let's assume the System is a Cinema Ticket Store and the Actor is a client that wants to buy a ticket. 1) The User tells the System that wants to buy some tickets, stating his client number. 2) The System confirms that the given client number is valid. 3) The User tells the System the movie that wants to see. 4) The System shows the set of available sessions and seats for that movie. 5) The System asks the user which session/seat he wants. 6) The User tells the System the chosen session/seat. This would be converted to: a) -----> tellClientNumber(clientNumber) b) <----- validClientNumber c) -----> tellMovieToSee(movie) d) <----- showsAvailableSeatsHours e) -----> tellSystemChosenSessionSeat(session, seat) I know that when we are dealing with SDD's we are still far away from coding. But I can't help trying to imagine how it how it would have been had I to convert it right away to code: I can understand 1) and 2). It's like if it was a C#/Java method with the following signature: boolean tellClientNumber(clientNumber) so I put both on the SDD. Then, we have the pair 3) 4). I can imagine that as something as: SomeDataStructureThatHoldsAvailableSessionsSeats tellSystemMovieToSee(movie) Now, the problem: From what I've come to understand, my lecturer says that we shouldn't make an operation on the SDD for 5) as we should only show operations from the Actor to the System and when the System is either presenting us data (as in c)) or validating sent data (such as in b)). I find this odd, as if I try to imagine this like a DOS app where you have to put your input sequencially, it makes sense to make an arrow even for 5). Why is this wrong? How should I try to visualize this? Thanks

    Read the article

  • Question about C# 4.0's generics covariance

    - by devoured elysium
    Having defined this interface: public interface IInputBoxService<out T> { bool ShowDialog(); T Result { get; } } Why does the following code work: public class StringInputBoxService : IInputBoxService<string> { ... } ... IInputBoxService<object> service = new StringInputBoxService(); and this doesn't?: public class IntegerInputBoxService : IInputBoxService<int> { ... } ... IInputBoxService<object> service = new IntegerInputBoxService(); Does it have anything to do with int being a value type? If yes, how can I circumvent this situation? Thanks

    Read the article

  • Using VS Code Snippets with Resharper

    - by devoured elysium
    I am trying to use Code Contract's Code Snippets but since I turned Resharper back on it doesn't recognize them. On the other hand, it is recognizing some snippets I've implemented myself in the past. Any ideia of what might be the problem? I'm specifically trying to use cr and ce, which I think, don't collide with any other snippets (at least from what I see in the intellisense). I'm using R# 5 with VS 2010 Thanks

    Read the article

  • Disposing a Bitmap through its Finalizer

    - by devoured elysium
    I have a complex program in which I have to first create, then use wrappers around bitmaps and send them across a lot of different classes. The problem in the end is deciding which classes should dispose the bitmaps. Most of the time the end classes don't know if they can indeed dispose the bitmap as the same bitmap can be used in several places. Also, I can't just copy the bitmaps because this is a kind of resource intensive algorithm and doing it would be dead slow. I looked up on reflector for Image/Bitmap's implementations and they seem to use the Dispose Pattern. So, even if I don't call Dispose(), the CLR will eventually call it some other time. Is it too bad if I just let the bitmaps be as they are, and let the finalizer take care of them?

    Read the article

  • Design issue when having classes implement different interfaces to restrict client actions

    - by devoured elysium
    Let's say I'm defining a game class that implements two different views: interface IPlayerView { void play(); } interface IDealerView { void deal(); } The view that a game sees when playing the game, and a view that the dealer sees when dealing the game (this is, a player can't make dealer actions and a dealer can't make player actions). The game definition is as following: class Game : IPlayerView, IDealerView { void play() { ... } void deal() { ... } } Now assume I want to make it possible for the players to play the game, but not to deal it. My original idea was that instead of having public Game GetGame() { ... } I'd have something like public IPlayerView GetGame() { ... } But after some tests I realized that if I later try this code, it works: IDealerView dealerView = (IDealerView)GameClass.GetGame(); this works as lets the user act as the dealer. Am I worrying to much? How do you usually deal with this patterns? I could instead make two different classes, maybe a "main" class, the dealer class, that would act as factory of player classes. That way I could control exactly what I would like to pass on the the public. On the other hand, that turns everything a bit more complex than with this original design. Thanks

    Read the article

  • Trouble deciding return type of a method that returns a SortedSet

    - by devoured elysium
    I am supposed to make a class that should be a container for an interval of values (like in mathematics). I have already decided that I'll use internally a SortedSet. One of the the things I'm supposed to implement is a method that "gets an ordered set with all the elements in the interval". class Interval { private SortedSet sortedSet = new something(); ... <<method that should return an ordered set of values>> } My question resides in what should be both the method's return type and name. Several hypothesis arise: SortedSet getSortedElements(); I am internally using a SortedSet, so I should return that type. I should state that intent in the method's name. SortedSet getElements(); I am internally using a SortedSet, but there's no point in stating that in the method name(I don't see a big point in this one). Set getElements(); I should try to always return the most basic type, thus I am returning a Set. By the contract and definition of the method, people already know all the elements are in order. Set getSortedElements(); For the method return type, the same as above. About the method name, you are stating clearly what this method is going to return: a set of elements that are sorted. I'm inclined to use 4. , but the others also seem alright. Is there a clear winner? Why?

    Read the article

  • Does Visual Studio 2010 support something like Eclipse's "Generate delegate methods"?

    - by devoured elysium
    Eclipse allows us to define a class as: interface MyInterface { void methodA(); int methodB(); } class A : MyInterface { MyInterface myInterface; } and then with this "Generate delegate methods", it will implement all needed methods for the interface, redirecting their logic to myInterface's methods: class A : MyInterface { MyInterface myInterface; public void methodA() { myInterface.methodA(); } public int methodB() { return myInterface.methodB(); } } Is it possible to accomplish the same with VS2010? And with R#? Thanks

    Read the article

  • Passing arguments between classes - use public properties or pass a properties class as argument?

    - by devoured elysium
    So let's assume I have a class named ABC that will have a list of Point objects. I need to make some drawing logic with them. Each one of those Point objects will have a Draw() method that will be called by the ABC class. The Draw() method code will need info from ABC class. I can only see two ways to make them have this info: Having Abc class make public some properties that would allow draw() to make its decisions. Having Abc class pass to draw() a class full of properties. The properties in both cases would be the same, my question is what is preferred in this case. Maybe the second approach is more flexible? Maybe not? I don't see here a clear winner, but that sure has more to do with my inexperience than any other thing. If there are other good approaches, feel free to share them. Here are both cases: class Abc1 { public property a; public property b; public property c; ... public property z; public void method1(); ... public void methodn(); } and here is approach 2: class Abc2 { //here we make take down all properties public void method1(); ... public void methodn(); } class Abc2MethodArgs { //and we put them here. this class will be passed as argument to //Point's draw() method! public property a; public property b; public property c; ... public property z; } Also, if there are any "formal" names for these two approaches, I'd like to know them so I can better choose the tags/thread name, so it's more useful for searching purposes. That or feel free to edit them.

    Read the article

  • What to do when using Contract.Assert(true) and the method must return something?

    - by devoured elysium
    I have a bit of code with the following logic: //pseudo-code foreach (element in elementList) { if (element is whatever) return element; } } In theory, there is always one element that is whatever, so this method should pose no problems. In any case, I've put an assertion on the end of the method just to be sure: //pseudo-code foreach (element in elementList) { if (element is whatever) return element; } } Contract.Assert(true, "Invalid state!"); The problem is that as this method has to return something, and the compiler doesn't understand that the assertion will break the program execution. Before using Contracts, in these kind of situations, I used to throw an Exception, which solved the problem. How would you handle this with Contract.Assert()? Returning null or default(element_type) after the Contract.Assert() call knowing it will never be called and shutting up the compiler? Or is there any other more elegant way of doing this? Thanks

    Read the article

< Previous Page | 1 2 3 4 5 6  | Next Page >