Search Results

Search found 254060 results on 10163 pages for 'stack oriented'.

Page 4/10163 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How to change the state of a singleton in runtime

    - by user34401
    Consider I am going to write a simple file based logger AppLogger to be used in my apps, ideally it should be a singleton so I can call it via public class AppLogger { public static String file = ".."; public void logToFile() { // Write to file } public static log(String s) { AppLogger.getInstance().logToFile(s); } } And to use it AppLogger::log("This is a log statement"); The problem is, what is the best time I should provide the value of file since it is a just a singleton? Or how to refactor the above code (or skip using singleton) so I can customize the log file path? (Assume I don't need to write to multiple at the same time) p.s. I know I can use library e.g. log4j, but consider it is just a design question, how to refactor the code above?

    Read the article

  • Use decorator and factory together to extend objects?

    - by TheClue
    I'm new to OOP and design pattern. I've a simple app that handles the generation of Tables, Columns (that belong to Table), Rows (that belong to Column) and Values (that belong to Rows). Each of these object can have a collection of Property, which is in turn defined as an enum. They are all interfaces: I used factories to get concrete instances of these products, depending on circumnstances. Now I'm facing the problem of extending these classes. Let's say I need another product called "SpecialTable" which in turn has some special properties or new methods like 'getSomethingSpecial' or an extended set of Property. The only way is to extend/specialize all my elements (ie. build a SpecialTableFactory, a SpecialTable interface and a SpecialTableImpl concrete)? What to do if, let's say, I plan to use standard methods like addRow(Column column, String name) that doesn't need to be specialized? I don't like the idea to inherit factories and interfaces, but since SpecialTable has more methods than Table i guess it cannot share the same factory. Am I wrong? Another question: if I need to define product properties at run time (a Table that is upgraded to SpecialTable at runtime), i guess i should use a decorator. Is it possible (and how) to combine both factory and decorator design? Is it better to use a State or Strategy pattern, instead?

    Read the article

  • Passing functions into other functions as parameters, bad practice?

    - by BlueHat
    We've been in the process of changing how our AS3 application talks to our back end and we're in the process of implementing a REST system to replace our old one. Sadly the developer who started the work is now on long term sick leave and it's been handed over to me. I've been working with it for the past week or so now and I understand the system, but there's one thing that's been worrying me. There seems to be a lot of passing of functions into functions. For example our class that makes the call to our servers takes in a function that it will then call and pass an object to when the process is complete and errors have been handled etc. It's giving me that "bad feeling" where I feel like it's horrible practice and I can think of some reasons why but I want some confirmation before I propose a re-work to system. I was wondering if anyone had any experience with this possible problem?

    Read the article

  • Law of Demeter in MVC regarding Controller-View communication

    - by Antonio MG
    The scenario: Having a Controller that controls a view composed of complex subviews. Each one of those subviews is a separated class in a separate file. For example, one of those subviews is called ButtonsView, and has a bunch of buttons. The Controller has to access those buttons. Would accessing those buttons like this: controllerMainView.buttonsView.firstButton.state(); be a violation of the LOD? On one hand, it could be yes because the controller is accessing the inner hierarchy of the view. On the other, a Controller should be aware of what happens inside the view and how is composed. Any thoughts?

    Read the article

  • How do I decide to which class a method should belong

    - by Eleeist
    I have TopicBusiness.class and PostBusiness.class. I have no problem with deciding into which class methods such as addPostToDatabase() or getAllPostsFromDatabase() should go. But what about getAllPostsFromTopic(TopicEntity topic) or getNumberOfPostsInTopic(TopicEntity topic)? Should the parameter be the deciding factor? So when the method takes TopicEntity as parameter it should belong to TopicBusiness.class? I am quite puzzled by this. EDIT: Some more info as requested. TopicBusiness.class and PostBusiness.class are classes holding all the business logic of the application concerning topics and posts respectively - that is fetching the data from database and/or performing some operations on them. TopicEntity is data (in this case representing single topic) fetched from database. getAllPostFromTopic(TopicEntity topic) gets all posts from database that belong to particular topic, while getNumberOfPostsInTopic(TopicEntity topic) performs database query and returns the number of posts that topic passed as parameter consists of.

    Read the article

  • How to decide to which class does a method belong

    - by Eleeist
    I have TopicBusiness.class and PostBusiness.class. I have no problem with deciding into which class methods such as addPostToDatabase() or getAllPostsFromDatabase() should go. But what about getAllPostsFromTopic(TopicEntity topic) or getNumberOfPostsInTopic(TopicEntity topic)? Should the parameter be the deciding factor? So when the method takes TopicEntity as parameter it should belong to TopicBusiness.class? I am quite puzzled by this.

    Read the article

  • Is it better to return NULL or empty values from functions/methods where the return value is not present?

    - by P B
    I am looking for a recommendation here. I am struggling with whether it is better to return NULL or an empty value from a method when the return value is not present or cannot be determined. Take the following two methods as an examples: string ReverseString(string stringToReverse) // takes a string and reverses it. Person FindPerson(int personID) // finds a Person with a matching personID. In ReverseString(), I would say return an empty string because the return type is string, so the caller is expecting that. Also, this way, the caller would not have to check to see if a NULL was returned. In FindPerson(), returning NULL seems like a better fit. Regardless of whether or not NULL or an empty Person Object (new Person()) is returned the caller is going to have to check to see if the Person Object is NULL or empty before doing anything to it (like calling UpdateName()). So why not just return NULL here and then the caller only has to check for NULL. Does anyone else struggle with this? Any help or insight is appreciated.

    Read the article

  • Any tips/tricks/resources on actually TEACHING a class on OOP? [closed]

    - by Sempus
    I may slowly be getting into teaching an Object-Orientated Programming class at my school in a year or two. I just graduated and work at my school as an Application Programmer. I'd first start off as a TA/grader and then slowly move into the Professor role. The class would be in Java. I always see resources on this fine site about HOW to program, but does anyone know any tips/tricks/resources on how to TEACH a programming class? It would be full of all different skills levels(but still semi-technical) so it would have to be a little more understandable than if it was just CS kids.

    Read the article

  • is it valid that a state machine can have more than one possible state for some transition?

    - by shankbond
    I have a requirement for a workflow which I am trying to model as a state machine, I see that there is more than one outcome of a given transition(or activity). Is it valid for a state machine to have more than one possible states, but only one state will be true at a given time? Note: This is my first attempt to model a state machine. Eg. might be: s1-t1-s2 s1-t1-s3 s1-t1-s4 where s1, s2, s3, s4 are states and t1 is transition/activity. A fictitious real world example might be: For a human, there can be two states: hungry, not hungry A basket can have only one item from: apple, orange. So, to model it we will have: hungry-pick from basket-apple found hungry-pick from basket-orange found apple found-eat-not hungry orange found-take juice out of it and then drink- not hungry

    Read the article

  • Search in Stack

    - by WPS
    Hi, I've a Java Stack created and some custom objects added to it. These objects contains unique id as one of their field. I need to get the index of that object in stack based on the unique name. Please find the example. class TestVO{ private String name; private String uniqueId; //getters and setters } public class TestStack{ public static void main(String args[]){ TestVO vo1=new TestVO(); TestVO vo2=new TestVO(); TestVO vo3=new TestVO(); vo1.setName("Test Name 1") vo1.setId("123") vo2.setName("Test name 2"); vo2.setId("234"); Stack<TestVO> stack=new Stack<TestVO>(); stack.add(vo1); stack.add(vo2); //I need to get the index of a VO from stack using it's unique ID } } Can someone please help me to implement this?

    Read the article

  • NPTL Default Stack Size Problem

    - by eyazici
    Hello, I am developing a multithread modular application using C programming language and NPTL 2.6. For each plugin, a POSIX thread is created. The problem is each thread has its own stack area, since default stack size depends on user's choice, this may results in huge memory consumption in some cases. To prevent unnecessary memory usage I used something similar to this to change stack size before creating each thread: pthread_attr_t attr; pthread_attr_init (&attr); pthread_attr_getstacksize(&attr, &st1); if(pthread_attr_setstacksize (&attr, MODULE_THREAD_SIZE) != 0) perror("Stack ERR"); pthread_attr_getstacksize(&attr, &st2); printf("OLD:%d, NEW:%d - MIN: %d\n", st1, st2, PTHREAD_STACK_MIN); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); /* "this" is static data structure that stores plugin related data */ pthread_create(&this->runner, &attr, (void *)(void *)this->run, NULL); EDIT I: pthread_create() section added. This did not work work as I expected, the stack size reported by pthread_attr_getstacksize() is changed but total memory usage of the application (from ps/top/pmap output) did not changed: OLD:10485760, NEW:65536 - MIN: 16384 When I use ulimit -s MY_STACK_SIZE_LIMIT before starting application I achieve the expected result. My questions are: 1-) Is there any portable(between UNIX variants) way to change (default)thread stack size after starting application(before creating thread of course)? 2-) Is it possible to use same stack area for every thread? 3-) Is it possible completely disable stack for threads without much pain?

    Read the article

  • stack and heap issue for iPhone memory management

    - by Forrest
    From this post I got know that the Objective-C runtime does not allow objects to be instantiated on the stack, but only on the heap; this means that you don’t have “automatic objects”, nor things like auto_ptr objects to help you manage memory; Someone give one example in post Objective C: Memory Allocation on stack vs. heap NSString* str = @"hello"; but this NSString is also not allocated in stack. Feel odd that this str is static. (Who can explain this ? ) Question here is that why there is no heap ? even mixing c++ together with Object C ? /////////////////////////////// Clear my question /////////////////////////////// I am confused , so questions are not clear. Let me put in this way. 1) All Object C objects should be alloc in stack ? ( I think yes ) 2)In C++, there are stack for memory, so for iOS app, also have stack ? ( I think yes ) 3) for iOS app, if only use Object C, so what is the usage of stack ? what kind of objects should use stack then ?

    Read the article

  • Implementing arrays using a stack

    - by Zack
    My programming language has no arrays, no lists, no pointers, no eval and no variable variables. All it has: Ordinary variables like you know them from most programming languages: They all have an exact name and a value. One stack. Functions provided are: push (add element to top), pop (remove element from top, get value) and empty (check if stack is empty) My language is turing-complete. (Basic arithmetics, conditional jumps, etc implemented) That means, it must be possible to implement some sort of list or array, right? But I have no idea how... What I want to achieve: Create a function which can retrieve and/or change an element x of the stack. I could easily add this function in the implementation of my language, in the interpreter, but I want to do it in my programming language. "Solution" one (Accessing an element x, counting from the stack top) Create a loop. Pop off the element from the stack top x times. The last element popped of is element number x. I end up with a destroyed stack. Solution two: Do the same as above, but store all popped off values in a second stack. Then you could move all elements back after you are done. But you know what? I don't have a second stack!

    Read the article

  • Write magic bytes to the stack to monitor its usage

    - by tkarls
    I have a problem on an embedded device that I think might be related to a stack overflow. In order to test this I was planning to fill the stack with magic bytes and then periodically check if the stack has overflowed by examining how much of my magic bytes that are left intact. But I can't get the routine for marking the stack to work. The application keeps crashing instantly. This is what I have done just at the entry point of the program. //fill most of stack with magic bytes int stackvar = 0; int stackAddr = int(&stackvar); int stackAddrEnd = stackAddr - 25000; BYTE* stackEnd = (BYTE*) stackAddrEnd; for(int i = 0; i < 25000; ++i) { *(stackEnd + i) = 0xFA; } Please note that the allocated stack is larger than 25k. So I'm counting on some stack space to already be used at this point. Also note that the stack grows from higher to lower addresses that's why I'm trying to fill from the bottom and up. But as I said, this will crash. I must be missing something here.

    Read the article

  • Stack & heap understanding question

    - by Petr
    Hi, I would really appreciate if someone could tell me whether I understand it well: class X { A a1=new A() //reference on the stack, object value on the heap a1.VarA=5; //on the stack - value type A a2=new A() //reference on the stack, object value on the heap a2.VarA=10; //on the stack - value type a1=a2; //on the stack, the target of a1 reference is updated to a2 value on the heap //also both a1 and a2 references are on the stack, while their "object" values on the heap. But what about VarA variable, its still pure value type? } class A { int VarA; }

    Read the article

  • Stack / base pointers in assembly

    - by flyingcrab
    I know this topic has been covered ad-naseum here, and other places on the internet - but hopefully the question is a simple one as I try to get my head around assembly... So if i understand correctly the ebp (base pointer) will point to the top of the stack, and the esp (stack pointer) will point to the bottom -- since the stack grows downward. esp therefore points to the 'current location'. So on a function call, once you've saved the ebp on the stack you insert a new stack frame - for the function. So in the case of the image below, if you started from N-3 you would go to N-2 with a function call. But when you are at N-2 - is your ebp == 25 and the esp == 24 (at least initially, before any data is placed on the stack)? Is this correct or am I of on a tangent here? Thanks!

    Read the article

  • Separation of memory oriented process and CPU oriented process

    - by Jeevan Dongre
    I am develops guy working for an e-commerce company I am running my e-commerce application built using ruby on rails spree commerce. I am presently running 2 medium instances in the production. One is a high memory instance which has 3.8 RAM and single Core CPU and another one is high CPU instance which has Dual Core CPU. Basically AWS calls it has m1.medium and c1.medium instance respectively. My question is it possible to separate the processes according the cpu intense and memory intense? So that all the cpu intense process can be made run in high cpu instance and all the memory intense process can be made to run in the high memory instances. Is any tool available to identify those process. Kindly give me some heads up. Thank you

    Read the article

  • How to write Haskell function to verify parentheses matching?

    - by Rizo
    I need to write a function par :: String -> Bool to verify if a given string with parentheses is matching using stack module. Ex: par "(((()[()])))" = True par "((]())" = False Here's my stack module implementation: module Stack (Stack, push, pop, top, empty, isEmpty) where data Stack a = Stk [a] deriving (Show) push :: a -> Stack a -> Stack a push x (Stk xs) = Stk (x:xs) pop :: Stack a -> Stack a pop (Stk (_:xs)) = Stk xs pop _ = error "Stack.pop: empty stack" top :: Stack a -> a top (Stk (x:_)) = x top _ = error "Stack.top: empty stack" empty :: Stack a empty = Stk [] isEmpty :: Stack a -> Bool isEmpty (Stk [])= True isEmpty (Stk _) = False So I need to implement a 'par' function that would test a string of parentheses and say if parentheses in it matches or not. How can I do that using a stack?

    Read the article

  • Determining the maximum stack depth

    - by Joa Ebert
    Imagine I have a stack-based toy language that comes with the operations Push, Pop, Jump and If. I have a program and its input is the toy language. For instance I get the sequence Push 1 Push 1 Pop Pop In that case the maximum stack would be 2. A more complicated example would use branches. Push 1 Push true If .success Pop Jump .continue .success: Push 1 Push 1 Pop Pop Pop .continue: In this case the maximum stack would be 3. However it is not possible to get the maximum stack by walking top to bottom as shown in this case since it would result in a stack-underflow error actually. CFGs to the rescue you can build a graph and walk every possible path of the basic blocks you have. However since the number of paths can grow quickly for n vertices you get (n-1)! possible paths. My current approach is to simplify the graph as much as possible and to have less possible paths. This works but I would consider it ugly. Is there a better (read: faster) way to attack this problem? I am fine if the algorithm produces a stack depth that is not optimal. If the correct stack size is m then my only constraint is that the result n is n = m. Is there maybe a greedy algorithm available that would produce a good result here?

    Read the article

  • C++ stack in Objective-C++

    - by helixed
    I'd like to use a C++ stack type in Objective-C, but I'm running into some issues. Here's a sample of what I would like to do: #import <stack> #import <UIKit/UIKit.h> @interface A : NSObject { stack<SEL> selectorStack; } @end Unfortunately, this doesn't compile. After messing around with the code for a while and trying different things, I can't seem to find a way to accomplish this. Can somebody tell me the best way to use a C++ stack within an Objective-C object or if it's even possible? Thanks. UPDATE: Well, KennyTM's answer worked on my example file, but for some reason when I tried to rename the class it quit working. Here's the code I have right now: #import <stack> #import <UIKit/UIKit.h> @interface MenuLayer : NSObject { std::stack<SEL> selectorStack; } @end The compiler spits out the following errors: stack: No such file or directory expected specifier-qualifier-list before 'std'

    Read the article

  • how to know location of return address on stack c/c++

    - by Dr Deo
    i have been reading about a function that can overwrite its return address. void foo(const char* input) { char buf[10]; //What? No extra arguments supplied to printf? //It's a cheap trick to view the stack 8-) //We'll see this trick again when we look at format strings. printf("My stack looks like:\n%p\n%p\n%p\n%p\n%p\n% p\n\n"); //%p ie expect pointers //Pass the user input straight to secure code public enemy #1. strcpy(buf, input); printf("%s\n", buf); printf("Now the stack looks like:\n%p\n%p\n%p\n%p\n%p\n%p\n\n"); } It was sugggested that this is how the stack would look like Address of foo = 00401000 My stack looks like: 00000000 00000000 7FFDF000 0012FF80 0040108A <-- We want to overwrite the return address for foo. 00410EDE Question: -. Why did the author arbitrarily choose the second last value as the return address of foo()? -. Are values added to the stack from the bottom or from the top? apart from the function return address, what are the other values i apparently see on the stack? ie why isn't it filled with zeros Thanks.

    Read the article

  • which metric(s) show the difference between object-oriented and procedural code

    - by twieger
    Which metric(s) could help to indicate that i have procedural code instead of object-oriented code? I would like to have a set of simple metrics, which indicate with a high probability, that the analyzed code contains procedural transaction scripts and an anemic domain model instead of following sound object-oriented design principles. Would be happy about any set of useful metrics and tools for measuring. Thanks, Thomas!

    Read the article

  • Is this good code? Linked List Stack Implementation

    - by Quik Tester
    I have used the following code for a stack implementation. The top keeps track of the topmost node of the stack. Now since top is a data member of the node function, each node created will have a top member, which ideally we wouldn't want. Firstly, is this good approach to coding? Secondly, will making top as static make it a better coding practice? Or should I have a global declaration of top? #include<iostream> using namespace std; class node { int data; node *top; node *link; public: node() { top=NULL; link=NULL; } void push(int x) { node *n=new node; n->data=x; n->link=top; top=n; cout<<"Pushed "<<n->data<<endl; } void pop() { node *n=new node; n=top; top=top->link; n->link=NULL; cout<<"Popped "<<n->data<<endl; delete n; } void print() { node *n=new node; n=top; while(n!=NULL) { cout<<n->data<<endl; n=n->link; } delete n; } }; int main() { node stack; stack.push(5); stack.push(7); stack.push(9); stack.pop(); stack.print(); } Any other suggestions welcome. I have also seen codes where there are two classes, where the second one has the top member. What about this? Thanks. :)

    Read the article

  • An Open Letter from Lyle Ekdahl, Group Vice President and General Manager, Oracle's JD Edwards

    - by Brian Dayton
    From Lyle Ekdahl, Group Vice President and General Manager, Oracle's JD Edwards As you may have heard, we recently announced some changes to the way Oracle will offer licensing of technology products with JD Edwards EnterpriseOne. Specifically, we have withdrawn from new sales the product known as JD Edwards EnterpriseOne Technology Foundation ("Blue Stack"). Our motivation for this change is simply to streamline licensing for our customers. Going forward, customers will license Oracle products from Oracle and IBM products from IBM. Customers who are currently licensed for Technology Foundation will continue to receive support--unchanged--through September 30, 2016. This announcement affects how customers license these IBM products; it does not affect Oracle's certification roadmap for IBM products with JD Edwards EnterpriseOne. Customers who are currently running their JD Edwards EnterpriseOne infrastructure using IBM platform components can continue to do so regardless of whether they license these components via Technology Foundation or directly from IBM. New customers choosing to run JD Edwards EnterpriseOne on IBM technology should license JD Edwards EnterpriseOne Core Tools from Oracle while licensing Infrastructure and any licenses of IBM products from IBM. For more information about this announcement, customers should refer to My Oracle Support article 1232453.1 Questions included in the "Frequently Asked Questions" document on My Oracle Support: Is Oracle dropping support for IBM DB2 and IBM WebSphere with JD Edwards EnterpriseOne? No. This announcement affects how customers license these IBM products; it does not affect Oracle's certification roadmap for these products. The JD Edwards EnterpriseOne matrix of supported databases, web servers, and portals remains unchanged, including planned support for IBM DB2, IBM WebSphere Application Server, and IBM WebSphere Portal. Customers who are currently running their JD Edwards EnterpriseOne infrastructure using IBM platform components can continue to do so regardless of whether they license these components via Technology Foundation or directly from IBM. As always, the timing and versions of such third-party certifications remain at Oracle's discretion. Does this announcement mean that Oracle is withdrawing support for JD Edwards EnterpriseOne on the IBM i platform? Absolutely not. JD Edwards EnterpriseOne support on the IBM i platform remains unchanged. This announcement simply states that customers will acquire Oracle products from Oracle and IBM products from IBM. In fact, as evidenced by the recent "IBM i Solution Edition for JD Edwards" offering, IBM and the JD Edwards product teams continue to innovate and offer attractive, cost-competitive solutions to the ERP marketplace. For more information about this offering see: http://www-03.ibm.com/systems/i/advantages/oracle/. I hope this clarifies any concerns. Let me know if you have any additional questions or concerns. -Lyle

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >