Search Results

Search found 3120 results on 125 pages for 'php5 oop'.

Page 47/125 | < Previous Page | 43 44 45 46 47 48 49 50 51 52 53 54  | Next Page >

  • Is it true that in most Object Oriented Programming Languages, an "i" in an instance method always r

    - by Jian Lin
    In the following code: <script type="text/javascript"> var i = 10; function Circle(radius) { this.r = radius; this.i = radius; } Circle.i = 123; Circle.prototype.area = function() { alert(i); } var c = new Circle(1); var a = c.area(); </script> What is being alerted? The answer is at the end of this question. I found that the i in the alert call either refers to any local (if any), or the global variable. There is no way that it can be the instance variable or the class variable even when there is no local and no global defined. To refer to the instance variable i, we need this.i, and to the class variable i, we need Circle.i. Is this actually true for almost all Object oriented programming languages? Any exception? Are there cases that when there is no local and no global, it will look up the instance variable and then the class variable scope? (or in this case, are those called scope?) the answer is: 10 is being alerted.

    Read the article

  • Graphic editor opensource project example on c++ underlying composite pattern

    - by G-71
    Can you tell me when I can see a some opensource project (only project on C++ language), which is simple graphic editor, ?ontaining following primitive (for example): an ellipse, a rectangle, a line. And desirable, that to be able to group this primitive in one primitive (for example, Word Grouping - Group). Composite pattern use is desirable in this project. I want to see how to organize classes, but more serious for me is to see how organize grouping operation. I searched for it on codeproject.com codeproject.com, codeplex.com, but not found this. I have already some source http://pastebin.com/xe4JF5PW But in my opinion, this code is dirty and ugly. Therefore, I want to see some opensource project for example. Thanks!

    Read the article

  • Which is the correct design pattern for my PHP application?

    - by user1487141
    I've been struggling to find good way to implement my system which essentially matches the season and episode number of a show from a string, you can see the current working code here: https://github.com/huddy/tvfilename I'm currently rewriting this library and want a nicer way to implement how the the match happens, currently essentially the way it works is: There's a folder with classes in it (called handlers), every handler is a class that implements an interface to ensure a method called match(); exists, this match method uses the regex stored in a property of that handler class (of which there are many) to try and match a season and episode. The class loads all of these handlers by instantiating each one into a array stored in a property, when I want to try and match some strings the method iterates over these objects calling match(); and the first one that returns true is then returned in a result set with the season and episode it matched. I don't really like this way of doing it, it's kind of hacky to me, and I'm hoping a design pattern can help, my ultimate goal is to do this using best practices and I wondered which one I should use? The other problems that exist are: More than one handler could match a string, so they have to be in an order to prevent the more greedy ones matching first, not sure if this is solvable as some of the regex patterns have to be greedy, but possibly a score system, something that shows a percentage of how likely the match is correct, i'd have no idea how to actually implement this though. I'm not if instantiating all those handlers is a good way of doing it, speed is important, but using best practices and sticking to design patterns to create good, extensible and maintainable code is my ultimate priority. It's worth noting the handler classes sometimes do other things than just regex matching, they sometimes prep the string to be matched by removing common words etc. Cheers for any help Billy

    Read the article

  • Session State Anti-Pattern

    - by Curiosity
    I know the SOLID principles and other design patterns fairly well and have been programming for some time now - seeing many a bit of code throughout the years. Having said that, I'm having trouble coming up with a name to give the pattern, or lack thereof, to bits of code I've been dealing with at a current engagement. The application is an ASP.NET C# WebForms application, backed by a SQL Server/Mainframe backend (more mainframe than backend) and it's riddled with Session State properties being accessed/mutated from multiple pages/classes. Accessing/mutating global variables/application state was usually shunned upon while I was in school. Apparently the creators of this magnificent application didn't think it was such a bad idea. Question: Is there a name for such a pattern/anti-pattern that relies so heavily on Session State? I'd like to call the pig by its name ...

    Read the article

  • Output of the following code

    - by terrific
    String s1 = "Amit"; //true String s2 = "Amit"; //true String s3 = new String("abcd"); //true String s4 = new String("abcd"); //false System.out.println(s1.equals(s2)); //true System.out.println((s1==s2)); //true System.out.println(s3.equals(s4)); //false System.out.println((s3==s4)); //false Assume it to be in main why the output of the above code is true true true false and not true true false false???

    Read the article

  • how to make objects globally accessible?

    - by fayer
    i have this code: class IC_Core { /** * Database * @var IC_Database */ public static $db = NULL; /** * Core * @var IC_Core */ protected static $_instance = NULL; private function __construct() { } public static function getInstance() { if ( ! is_object(self::$_instance)) { self::$_instance = new self(); self::initialize(self::$_instance); } return self::$_instance; } private static function initialize(IC_Core $IC_Core) { self::$db = new IC_Database($IC_Core); } } but when i wanna access IC_Database with: $IC = IC_Core::getInstance(); $IC->db->add() // it says that its not an object. i think the problem lies in self::$db = new IC_Database($IC_Core); but i dont know how to make it work. could someone give me a hand=) thanks!

    Read the article

  • How can I use Object Oriented Javascript to interact with HTML Objects

    - by Steve
    I am very new to object orientated javascript, with experience writing gui's in python and java. I am trying to create html tables that I can place in locations throughout a webpage. Each html table would have two css layouts that control if it is selected or not. I can write all of the interaction if I only have one table. It gets confusing when I have multiple tables. I am wondering how to place these tables throughout a blank webpage and then access the tables individually. I think I am having trouble understanding how inheritance and hierarchy works in javascript/html. NOTE: I am not asking how to make a table. I am trying to dynamically create multiple tables and place them throughout a webpage. Then access their css independently and change it (move them to different locations or change the way the look, independently of the other tables).

    Read the article

  • How do you determine how coarse or fine-grained a 'responsibility' should be when using the single r

    - by Mark Rogers
    In the SRP, a 'responsibility' is usually described as 'a reason to change', so that each class (or object?) should have only one reason someone should have to go in there and change it. But if you take this to the extreme fine-grain you could say that an object adding two numbers together is a responsibility and a possible reason to change. Therefore the object should contain no other logic, because it would produce another reason for change. I'm curious if there is anyone out there that has any strategies for 'scoping', the single-responsibility principle that's slightly less objective?

    Read the article

  • Is this a problem typically solved with IOC?

    - by Dirk
    My current application allows users to define custom web forms through a set of admin screens. it's essentially an EAV type application. As such, I can't hard code HTML or ASP.NET markup to render a given page. Instead, the UI requests an instance of a Form object from the service layer, which in turn constructs one using a several RDMBS tables. Form contains the kind of classes you would expect to see in such a context: Form= IEnumerable<FormSections>=IEnumerable<FormFields> Here's what the service layer looks like: public class MyFormService: IFormService{ public Form OpenForm(int formId){ //construct and return a concrete implementation of Form } } Everything works splendidly (for a while). The UI is none the wiser about what sections/fields exist in a given form: It happily renders the Form object it receives into a functional ASP.NET page. A few weeks later, I get a new requirement from the business: When viewing a non-editable (i.e. read-only) versions of a form, certain field values should be merged together and other contrived/calculated fields should are added. No problem I say. Simply amend my service class so that its methods are more explicit: public class MyFormService: IFormService{ public Form OpenFormForEditing(int formId){ //construct and return a concrete implementation of Form } public Form OpenFormForViewing(int formId){ //construct and a concrete implementation of Form //apply additional transformations to the form } } Again everything works great and balance has been restored to the force. The UI continues to be agnostic as to what is in the Form, and our separation of concerns is achieved. Only a few short weeks later, however, the business puts out a new requirement: in certain scenarios, we should apply only some of the form transformations I referenced above. At this point, it feels like the "explicit method" approach has reached a dead end, unless I want to end up with an explosion of methods (OpenFormViewingScenario1, OpenFormViewingScenario2, etc). Instead, I introduce another level of indirection: public interface IFormViewCreator{ void CreateView(Form form); } public class MyFormService: IFormService{ public Form OpenFormForEditing(int formId){ //construct and return a concrete implementation of Form } public Form OpenFormForViewing(int formId, IFormViewCreator formViewCreator){ //construct a concrete implementation of Form //apply transformations to the dynamic field list return formViewCreator.CreateView(form); } } On the surface, this seems like acceptable approach and yet there is a certain smell. Namely, the UI, which had been living in ignorant bliss about the implementation details of OpenFormForViewing, must possess knowledge of and create an instance of IFormViewCreator. My questions are twofold: Is there a better way to achieve the composability I'm after? (perhaps by using an IoC container or a home rolled factory to create the concrete IFormViewCreator)? Did I fundamentally screw up the abstraction here?

    Read the article

  • Extending a form field to add new validations.

    - by duallain
    I've written an app that uses forms to collect information that is then sent in an email. Many of these forms have a filefield used to attach files to the email. I'd like to validate two things, the size of the file (to ensure the emails are accepted by our mail server. I'd also like to check the file extension, to discourage attaching file types not useable for our users. (This is the python class I'm trying to extend) class FileField(Field): widget = FileInput default_error_messages = { 'invalid': _(u"No file was submitted. Check the encoding type on the form."), 'missing': _(u"No file was submitted."), 'empty': _(u"The submitted file is empty."), 'max_length': _(u'Ensure this filename has at most %(max)d characters (it has %(length)d).'), } def __init__(self, *args, **kwargs): self.max_length = kwargs.pop('max_length', None) super(FileField, self).__init__(*args, **kwargs) def clean(self, data, initial=None): super(FileField, self).clean(initial or data) if not self.required and data in EMPTY_VALUES: return None elif not data and initial: return initial # UploadedFile objects should have name and size attributes. try: file_name = data.name file_size = data.size except AttributeError: raise ValidationError(self.error_messages['invalid']) if self.max_length is not None and len(file_name) > self.max_length: error_values = {'max': self.max_length, 'length': len(file_name)} raise ValidationError(self.error_messages['max_length'] % error_values) if not file_name: raise ValidationError(self.error_messages['invalid']) if not file_size: raise ValidationError(self.error_messages['empty']) return data

    Read the article

  • how to implement a callback in runnable to update other swing class

    - by wizztjh
    I have a thread like this public class SMS { class Read implements Runnable { Read(){ Thread th = new Thread(this); th.start(); } @Override public void run() { // TODO Auto-generated method stub while (true){ Variant SMSAPIReturnValue = SMSAPIJava.invoke("ReadSMS"); if (SMSAPIReturnValue.getBoolean()){ String InNumber = SMSAPIJava.getPropertyAsString("MN"); String InMessage = SMSAPIJava.getPropertyAsString("MSG"); } } } } } How do I update the message to another GUI class in the same package(I understand how to put nested class to another package ....). Should I implement a callback function in SMS class? But how? Or should I pass in the Jlabel into the class?

    Read the article

  • How can i split up a component using cfinclude and still use inheritance?

    - by rip747
    Note: this is just a simplized example of what i'm trying to do to get the idea across. The problem I'm having is that I want to use cfinclude inside cfcomponent so that i can group like methods into separate files for more manageability. The problem I'm running into is when i try to extend another component that also uses cfinclude to manage it's method as demostrated below. Note that ComponentA extends ComponentB: ComponentA ========== <cfcomponent output="false" extends="componentb"> <cfinclude template="componenta/methods.cfm"> </cfcomponent> componenta/methods.cfm ====================== <cffunction name="a"><cfreturn "componenta-a"></cffunction> <cffunction name="b"><cfreturn "componenta-b"></cffunction> <cffunction name="c"><cfreturn "componenta-c"></cffunction> <cffunction name="d"><cfreturn super.a()></cffunction> ComponentB ========== <cfcomponent output="false"> <cfinclude template="componentb/methods.cfm"> </cfcomponent> componentb/methods.cfm ====================== <cffunction name="a"><cfreturn "componentb-a"></cffunction> <cffunction name="b"><cfreturn "componentb-b"></cffunction> <cffunction name="c"><cfreturn "componentb-c"></cffunction> The issue is that when i try to initialize ComponentA I get an the error: "Routines cannot be declared more than once. The routine a has been declared twice in different templates." The whole reason for this is because when you use cfinclude it's evaluated at RUN TIME instead of COMPILE TIME. Short of moving the methods into the components themselves and eliminating the use of cfinclude, how can i get around this or does someone have a better idea splitting up large components?

    Read the article

  • How to properly dispose of an object

    - by VoodooChild
    Hi Guys, I am experiencing something weird and have a workaround already, but I don't think I understood it well. If I call the Method below numerous times within a class: public void Method() { Foo a = new Foo(); a.Delegate1Handler = ViewSomething(); } So I am reinitializing "a" every time but for some reason a.Delegate1Handler is still around from the previous initialization, and therefore ViewSomething() is called again and again and again.... I feel like I am forgetting something critical here? Foo's guts look like: public delegate void Delegate1(T t); public Delegate1 Delegate1Handler { get; set; }

    Read the article

  • C# and Objects/Classes

    - by user1192890
    I have tried to compile code from Deitel's C# 2010 for programmers. I copied it exactly out of the book, but it still can't find main, even though I declared it in one of the classes. Here is a look at the two classes: For GradeBookTest: // Fig. 4.2: GradeBookTest.cs // Create a GradeBook object and call its DisplayMessage method. public class GradeBookTest { // Main method begins program execution public static void Main(string[] args) { // create a GradeBook object and assign it to myGradeBook GradeBook myGradeBook = new GradeBook(); // call myGradeBook's DisplayMessage method myGradeBook.DisplayMessage(); } // end Main } // end class GradeBookTest Now for the GradeBook class: // Fig. 4.1: GradeBook.cs // Class declaration with one method. using System; public class GradeBook { // display a welcome message to the GradeBook user public void DisplayMessage() { Console.WriteLine( "Welcome to the Grade Book!" ); } // end method DisplayMessage } // end class GradeBook That is how I copied them. Here is how they appeared in the book: 1 // Fig. 4.2: GradeBookTest.cs 2 // Create a GradeBook object and call its DisplayMessage method. 3 public class GradeBookTest 4 { 5 // Main method begins program execution 6 public static void Main( string[] args ) 7 { 8 // create a GradeBook object and assign it to myGradeBook 9 GradeBook myGradeBook = new GradeBook(); 10 11 // call myGradeBook's DisplayMessage method 12 myGradeBook.DisplayMessage(); 13 } // end Main 14 } // end class GradeBookTest and // Fig. 4.1: GradeBook.cs // Class declaration with one method. using System; public class GradeBook { // display a welcome message to the GradeBook user public void DisplayMessage() { Console.WriteLine( "Welcome to the Grade Book!" ); } // end method DisplayMessage } // end class GradeBook I don't see why they are not working. Right now I am using Visual Studio Pro 2010. Any Thoughts?

    Read the article

  • OO C++ - Virtual Methods

    - by Phorce
    Just a really quick question here. I'm using virtual functions to read in from a text file. Now, it's virtual because in one aspect I want the values to be normalised, and, in the other respect I don't want them to be normalised. I have tried to do this: bool readwav(string theFile, 'native'); So in theory, if the 'native' is used, this method should be called, however, if 'double' is called then a different version of the method is called. Same for if the value is empty, it should just perform the native option. First question, why doesn't the declaration above work? Also, is this the best route to go down? Or, would it be better to have just one class method that switches between the options. Thanks :)

    Read the article

  • How to Execute Base Class's Method Before Implementors's Method?

    - by DaveDev
    I have the following page public partial class GenericOfflineCommentary : OfflineFactsheetBase { } where OfflineFactsheetBase is defined as public class OfflineFactsheetBase : System.Web.UI.Page { public OfflineFactsheetBase() { this.Load += new EventHandler(this.Page_Load); this.PreInit += new EventHandler(this.Page_PreInit); } protected void Page_PreInit(object sender, EventArgs e) { if (Request.QueryString["data"] != null) { this.PageData = StringCompressor.DecompressString(Request.QueryString["data"]); this.ExtractPageData(); } } } OfflineFactsheetBase has the following virtual method: public virtual void ExtractPageData() { // get stuff relevant to all pages that impmement OfflineFactsheetBase } which is implemented in all pages that impmement OfflineFactsheetBase as follows: public partial class GenericOfflineCommentary : OfflineFactsheetBase { public override void ExtractPageData() { // get stuff relevant to an OfflineCommentary page. } } Currently, only GenericOfflineCommentary's ExtractPageData() is firing. How can I modify this to first run OfflineFactsheetBase's ExtractPageData() and then GenericOfflineCommentary's? edit: I'm trying to avoid having to call base.ExtractPageData() in every implementor. Is this possible?

    Read the article

  • example for Singleton pattern

    - by JavaUser
    Hi, Please give me a real time example for singleton pattern . Different threads accessing a shared file is singleton or not ? Since each thread access the same instance of the file not individual instances of their own .

    Read the article

  • where are the frameworks for creating libraries?

    - by fayer
    whenever i create a php library (not a framework) i tend to reinvent everything everytime. "where to put configuration options" "which design pattern to use here" "how should all the classes extend each other" and so on... then i think, isn't there a good library framework to use anywhere? it's like a framework for a web application (symfony, cakephp...) but instead of creating a web application, this framework will help coder to create a library, providing all the standard structure and classes (observer pattern, dependency injection etc). i think that will be the next major thing if not available right now. in this way there will be a standard to follow when creating libraries, or else, it's like a djungle when everyone creates their own structure, and a lot of coders just code without thinking of reusability etc. there isn't any framework for creating libraries at the moment? if not, don't u agree with me that this is the way to do it, with a library framework? cause i am really throwing a lot of time (weeks!) just thinking about how to organize things, both in code and file level, when i should just start to code the logic. share your thoughts!

    Read the article

  • How would I associate a "Note" class to 4+ classes without creating lookup table for each associatio

    - by Gthompson83
    Im creating a project tasklist application. I have project, section, task, issue classes, and would like to use one class to be able to add simple notes to any object instance of those classes. The task, issue tables both use a standard identity field as a primary key. The section table has a two field primary key. The project table has a single int primary key defined by the user. Is there a way to associate the note class with each of these without using a seperate lookup table for each class? I'm not so sure my original idea is a decent way to implement this. I considered the following (each variable mapping to a field n the notes table. Private _NoteId As Integer Private _ProjectId As Integer Private _SectionId As Integer Private _SectionId2 As Integer Private _TaskId As Integer Private _IssueId As Integer Private _Note As String Private _UserId As Guid Then I would be able to write seperate methods (getProjectNotes, getTaskNotes) to get notes attached to each class. I started writing this a few weeks ago but got pulled away before i could finish. When revisiting this code today my first thought "this is retarded". Thoughts on drawbacks to this design?

    Read the article

  • Set The Progress Bar Over 100% C#

    - by PhaDaPhunk
    its my first time using a ProgressBar in c#. The idea is to use the ProgressBar as an health bar in a simple game. The thing is I think the bar's maximum value is 100% but i would like to give it a higher value like let's say 1000% or, not sure if it's possible, give the bar an integer value instead of a percentage. progressBar1.Increment(100); This is where I initialize the health to 100points. Even if I use this syntax: progressBar1.Increment(1000); And I subtract : progressBar1.Increment(-25); The player is loosing 1/4 of is life as if he only had 100 Health Points. Any idea how I could change the maximum Bar value? Thanks in advance.

    Read the article

  • Access to an "upper" instance of a class from another instance of a different class

    - by BorrajaX
    Hello everyone! I have a tricky question and probably what I want to do is not even possible but... who knows... Python seems very flexible and powerful... I'd like to know if there's a way to access to the class (or its fields) where an object is instanciated. Let's say I have: def Class1: def __init__(self): self.title = "randomTitle" self.anotherField = float() self.class2Field = Class2() and the class whose type will be the class2Field: def Class2: def __init__(self): self.field1 = "" self.field2 = "" # . . . # I'd like to know if there's a way to access the instance of Class1 from the instance of Class2 that is declared in Class1 (meaning, accessing the fields of Class1 from the variable self.class2Field in that Class1 instance) I know I can always change the init in Class2 to accept a Class1 parameter, but I'd like to know if there's another way of "climbing" through the class hierachy... Thank you very much!

    Read the article

< Previous Page | 43 44 45 46 47 48 49 50 51 52 53 54  | Next Page >