Search Results

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

Page 50/125 | < Previous Page | 46 47 48 49 50 51 52 53 54 55 56 57  | Next Page >

  • How to call object's method from constructor?

    - by Kirzilla
    Hello, var Dog = function(name) { this.name = name; this.sayName(); } Dog.prototype.sayName = function() { alert(this.name); } I'm creating new instance of Dog object, but method sayName() is undefined. Why? Or maybe I should do something like (but I can't see difference)... var Dog = function(name) { this.name = name; this.prototype.sayName = function() { alert(this.name); } } Thank you.

    Read the article

  • how are association, aggregation and composition written?

    - by ajsie
    i have read some posts about the differences between these 3 relationships and i think i get the point. i just wonder, are all these written the same when coding? question 1: all 3 are just a value of the object type in a instance variable? class A { public $b = '' public function __construct($object) { $this->b = $object // <-- could be a association, aggregation or a composition relation? } } question 2: does it have to be an instance variable or can it be a static one? class A { public static $b = '' // <-- nothing changed? public function __construct($object) { $this->b = $object } } question 3: is there a difference in where the object is created? i tend to think that composition object is created inside the object: class A { public $b = '' public function __construct() { $this->b = new Object // is created inside the object } } and aggregation/association is passed through a constructor or another method: class A { public $b = '' public function __construct($object) { // passed through a method $this->b = $object } } question 4: why/when is this important to know. do i have to comment an object inside another what relation its about or do you do it in an UML diagram? could someone shed a light on these questions. thanks!

    Read the article

  • Generic overloading tells me this is the same function. Not agree.

    - by serhio
    base class: Class List(Of T) Function Contains(ByVal value As T) As Boolean derived class: Class Bar : List(Of Exception) ' Exception type as example ' Function Contains(Of U)(ByVal value As U) As Boolean compiler tells me that that two are the same, so I need to declare Overloads/new this second function. But I want use U to differentiate the type (one logic) like NullReferenceException, ArgumentNull Exception, etc. but want to leave the base function(no differentiation by type - other logic) as well.

    Read the article

  • Is it good practise to blank out inherited functionality that will not be used?

    - by Timo Kosig
    I'm wondering if I should change the software architecture of one of my projects. I'm developing software for a project where two sides (in fact a host and a device) use shared code. That helps because shared data, e.g. enums can be stored in one central place. I'm working with what we call a "channel" to transfer data between device and host. Each channel has to be implemented on device and host side. We have different kinds of channels, ordinary ones and special channels which transfer measurement data. My current solution has the shared code in an abstract base class. From there on code is split between the two sides. As it has turned out there are a few cases when we would have shared code but we can't share it, we have to implement it on each side. The principle of DRY (don't repeat yourself) says that you shouldn't have code twice. My thought was now to concatenate the functionality of e.g. the abstract measurement channel on the device side and the host side in an abstract class with shared code. That means though that once we create an actual class for either the device or the host side for that channel we have to hide the functionality that is used by the other side. Is this an acceptable thing to do: public abstract class MeasurementChannelAbstract { protected void MethodUsedByDeviceSide() { } protected void MethodUsedByHostSide() { } } public class DeviceMeasurementChannel : MeasurementChannelAbstract { public new void MethodUsedByDeviceSide() { base.MethodUsedByDeviceSide(); } } Now, DeviceMeasurementChannel is only using the functionality for the device side from MeasurementChannelAbstract. By declaring all methods/members of MeasurementChannelAbstract protected you have to use the new keyword to enable that functionality to be accessed from the outside. Is that acceptable or are there any pitfalls, caveats, etc. that could arise later when using the code?

    Read the article

  • Object Oriented vs Relational Databases

    - by Dan
    Objects oriented databases seem like a really cool idea to me, no need to worry about mapping your domain model to your database model, no messing around with sql or ORM tools. The way I understand it, relational DBs offer some advantages when there is massive amounts of data, and searching an indexing need to be done. To my mind 99% of websites are not massive, and enterprise issues never need to be thought about, so why arn't OO DBs more widely used?

    Read the article

  • what is the difference between static class and normal class?

    - by Phsika
    when i prefer static or normal class? Or what is the difference between them? using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace staticmethodlar { class Program { static void Main(string[] args) { SinifA.method1(); } } static class SinifA { public static void method1() { Console.WriteLine("Deneme1"); } } public static class SinifB { public static void method2() { Console.WriteLine("Deneme2"); } } public class sinifC { public void method3() { Console.WriteLine("Deneme3"); } } public class sinifD : sinifC { void method4() { Console.WriteLine("Deneme4"); } sinifC sinifc = new sinifC(); // i need to use it:) } }

    Read the article

  • Hash Tables - Java

    - by Antony
    Am about to do a homework, and i need to store quite a lot of information (Dictionary) in a data structure of my choice. I heard people in my classroom saying hash-tables are the way to go. How come?

    Read the article

  • How value objects are saving and loading?

    - by yeraycaballero
    Since there isn't respositories for value objects. How can I load all value objects? Suppose we are modeling a blog application and we have this classes: Post (Entity) Comment (Value object) Tag (Value object) PostsRespository (Respository) I Know that when I save a new post, its tags are saving with it in the same table. But how could I load all tags of all posts. Has PostsRespository got a method to load all tags? I usually do it, but I want to know others opinions

    Read the article

  • Ways to make (relatively) safe assumptions about the type of concrete subclasses?

    - by Kylotan
    I have an interface (defined as a abstract base class) that looks like this: class AbstractInterface { public: bool IsRelatedTo(const AbstractInterface& other) const = 0; } And I have an implementation of this (constructors etc omitted): class ConcreteThing { public: bool IsRelatedTo(const AbstractInterface& other) const { return m_ImplObject.has_relationship_to(other.m_ImplObject); } private: ImplementationObject m_ImplObject; } The AbstractInterface forms an interface in Project A, and the ConcreteThing lives in Project B as an implementation of that interface. This is so that code in Project A can access data from Project B without having a direct dependency on it - Project B just has to implement the correct interface. Obviously the line in the body of the IsRelatedTo function cannot compile - that instance of ConcreteThing has an m_ImplObject member, but it can't assume that all AbstractInterfaces do, including the other argument. In my system, I can actually assume that all implementations of AbstractInterface are instances of ConcreteThing (or subclasses thereof), but I'd prefer not to be casting the object to the concrete type in order to get at the private member, or encoding that assumption in a way that will crash without a diagnostic later if this assumption ceases to hold true. I cannot modify ImplementationObject, but I can modify AbstractInterface and ConcreteThing. I also cannot use the standard RTTI mechanism for checking a type prior to casting, or use dynamic_cast for a similar purpose. I have a feeling that I might be able to overload IsRelatedTo with a ConcreteThing argument, but I'm not sure how to call it via the base IsRelatedTo(AbstractInterface) method. It wouldn't get called automatically as it's not a strict reimplementation of that method. Is there a pattern for doing what I want here, allowing me to implement the IsRelatedTo function via ImplementationObject::has_relationship_to(ImplementationObject), without risky casts? (Also, I couldn't think of a good question title - please change it if you have a better one.)

    Read the article

  • Automatically selecting and creating class objects

    - by Omin
    Lets say that we have a box class: class Box { private int width; private int height; //Box Constructor public Box( int height ) { this.height = height; width = 450; } } and a series of Box objects in our main: Box Box1 = new Box(147); Box Box2 = new Box(178); Box Box3 = new Box(784); Is there a way to use a "for" loop to go through these objects? Also, how would you make the computer create class objects for us? eg. create 10 objects using: for( int i=0; i>10; i++) { //method }

    Read the article

  • How should I lay-out my PHP login class?

    - by ThinkingInBits
    So, there is going to be one login form; however 1 of 3 types of members will be signing in member_type_a, member_type_b, member_type_c all of whom have some of the same properties, and some whom may have specific methods and/or properties to them. I want the class to be saved to a session variable for use with member area pages. Any suggestions on applicable design patterns?

    Read the article

  • javascript function object's inheritFrom method

    - by gawpertron
    I've come across this.inheritFrom that enables you to inherit from a super class. var superClass = function() { this.foo = 'foo'; this.bar = 'bar'; } var subClass = function() { this.inheritFrom = superClass; this.inheritFrom(); this.myFunction = function() { return this.foo; }; } I've looked in Mozilla and MSDN, but I can't seem to find it documented any where. As far as I can see it works in IE6 and Firefox 3. Any reason why it wouldn't be documented?

    Read the article

  • Objective-C inheritance; calling overriden method from superclass?

    - by anshuchimala
    Hello, I have an Objective-C class that has a method that is meant to be overridden, which is uses in a different method. Something like this: @interface BaseClass - (id)overrideMe; - (void)doAwesomeThings; @end @implementation BaseClass - (id)overrideMe { [self doesNotRecognizeSelector:_cmd]; return nil; } - (void)doAwesomeThings { id stuff = [self overrideMe]; /* do stuff */ } @end @interface SubClass : BaseClass @end @implementation SubClass - (id)overrideMe { /* Actually do things */ return <something>; } @end However, when I create a SubClass and try to use it, it still calls overrideMe on the BaseClass and crashes due to doesNotRecognizeSelector:. (I'm not doing a [super overrideMe] or anything stupid like that). Is there a way to get BaseClass to call the overridden overrideMe?

    Read the article

  • 1067: Implicit coercion of a value of type theplayclass to an unrelated type main

    - by Minelava
    I need help because I want to create a gameover screen that display score. However, there's an error that prevent me from transferring the score from theplayclass.as to thegameoverclass.as. Are there ways to pass a value to another movieclip without causing any errors. I refer the source code from this website : http://www.emanueleferonato.com/2008/12/17/designing-the-structure-of-a-flash-game-as3-version/ Here's the error C:\Users\xxx\Downloads\Migrate\test\theplayclass.as, Line 54, Column 41 1067: Implicit coercion of a value of type theplayclass to an unrelated type main. main.as package { import flash.display.MovieClip; import flash.events.Event; public class main extends MovieClip { public var playClass:theplayclass; public var gameOverClass:thegameoverclass; public function main() { showWin(); } public function showWin() { playClass = new theplayclass(this); addChild(playClass); } public function showGameOver() { gameOverClass = new thegameoverclass(this); addChild(gameOverClass); removeChild(playClass); playClass = null; } } } theplayclass.as package { import flash.display.MovieClip; import flash.events.*; public class theplayclass extends MovieClip { private var mainClass:main; var gameScore:Number; var gameOverScore:thegameoverclass; public function theplayclass(passedClass:main) { mainClass = passedClass; scoreText.text ="0"; gameScore = 0; win.addEventListener(MouseEvent.CLICK, showwinFunction); next.addEventListener(MouseEvent.CLICK, showgameoverFunction); addEventListener(Event.ADDED_TO_STAGE, addToStage); addEventListener(Event.ENTER_FRAME, changeScore); } public function addToStage(e:Event):void { this.x = 0; this.y = 0; } private function showwinFunction(e:MouseEvent):void { gameScore+=50; } private function changeScore(e:Event):void { scoreText.text =""+gameScore; } public function showgameoverFunction(e:MouseEvent) { mainClass.showGameOver(); gameOverScore = new thegameoverclass(this); gameOverScore.setTextScore(gameScore); } } } thegameoverclass.as package { import flash.display.MovieClip; import flash.events.MouseEvent; import flash.events.*; public class thegameoverclass extends MovieClip { var mainClass:main; var scorePoints:Number; public function thegameoverclass(passedClass:main) { mainClass = passedClass; finalScore.text = "test"; } public function setTextScore(textToSet:Number) { finalScore.text = ""+scorePoints; } } }

    Read the article

  • Is it possible to create ostream object, which outputs to multiple destinations?

    - by fiktor
    In 0-th approximation I have a class class MyClass{ public: ... std::ostream & getOStream(){return f;} private: ofstream f; ... }; Which is used sometimes in the following way: MyClass myclass; myclass.getOStream()<<some<<information<<printed<<here; But now I want to change the class MyClass, so that information will be printed both to f and to std::out, i.e. I want the above line to be equivalent to myclass.f<<some<<information<<printed<<here; std::cout<<some<<information<<printed<<here; I don't know any good way to do that. Do you? Is there any standard solution (for example in stl or in boost)? P.S. I tried to search on this, but it seems that I don't know good keywords. Words multiple, output, ostream, C++, boost seem to be too general.

    Read the article

  • Get information from a higher class?

    - by Clint Davis
    I don't know really how to word the question so please bear with me... I have 3 classes: Server, Database, and Table. Each class has a "Name" property. How I want it to work is that each server can have multiple databases and each database can have multiple tables. So in the Server class I have this property. Private _databases As List(Of Database) Public Property Databases() As List(Of Database) Get Return _databases End Get Set(ByVal value As List(Of Database)) _databases = value End Set End Property And I have something similar in the Database class for the tables. This works fine now because I can do something like this to get all the databases in the server. For Each db In s.Databases 's being the server object Debug.Print(db.Name) Next I would like to expand these classes. I want the server class to handle all the connection information and I would like the other classes to use the server class's connection information in them. For example, I setup a server class and set the connection string to the server. Then I want the database class to use serverclass.connectionstring property to connect to the server and get a list of all the databases. But I want to keep that code in the database class. How can I do this? I've attached some code of what I want to do. Public Class Server Private _name As String Public Property Name() As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property Private _databases As List(Of Database) Public Property Databases() As List(Of Database) Get Return _databases End Get Set(ByVal value As List(Of Database)) _databases = value End Set End Property End Class '-----New class Public Class Database Private _name As String Public Property Name() As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property Private _tables As List(Of Table) Public Property Tables() As List(Of Table) Get Return _tables End Get Set(ByVal value As List(Of Table)) _tables = value End Set End Property 'This is where I need help! Private Sub LoadTables () dim connectionstring as string = server.connectionstring 'Possible? 'Do database stuff End Class Thanks for reading!

    Read the article

  • Inheriting and overriding interfaces in C#

    - by Daniel A. White
    Please note: I am writing this question. I have these interfaces in a library/framework I am working on: interface IRepository<TKey,TModel> { void Remove(TModel entity); } interface IRepository<T> : IRepository<int, T> { } interface ISoftDeleteRepository<TKey,TModel> : IRepository<TKey, TModel> { } interface ISoftDeleteRepository<TModel> : ISoftDeleteRepository<int, TModel>, IRepository<TModel> { } and these implementations class Repository : IRepository { void Remove(TModel entity) { // actually Delete } } interface IRepository<T> : IRepository<int, T> { } interface ISoftDeleteRepository<TKey,TModel> : IRepository<TKey, TModel> { } interface ISoftDeleteRepository<TModel> : ISoftDeleteRepository<int, TModel>, IRepository<TModel> { }

    Read the article

  • how to make functions global?

    - by fayer
    i'm trying to follow DRY and i've got some functions i have to reuse. i put them all as static functions in a class and want to use them in another class. what is the best way to make them available to a class. cause i can't extend the class, its already extended. should/could i use composition? what is best practice? thanks!

    Read the article

  • Interesting OOPS puzzle

    - by user3714387
    Recently, faced the below question from one of the interviewer. Initially thought that the question was wrong, but the interviewer mentioned there is solution for this. Quite interesting. Can anyone shed light please ? Program as below. public class BaseHome { public static void main() { Console.WriteLine("A"); } } Required output : B A C Condition : Should not make any change in the Main function. Should not create any additional class. Please advice if this can be done with the condition met.

    Read the article

  • Multiple Inheritance Debates II: according to Stroustrup

    - by asksuperuser
    I know very well about the traditional arguments about why Interface Inheritance is prefered to multiple inheritance, there has been already a post here : http://stackoverflow.com/questions/191691/should-c-include-multiple-inheritance But according to Stroustrup the real reason why Microsoft and Sun decided to get rid off multiple inheritance is that they have vested interest to do so: instead of putting features in the languages, they put in frameworks so that people then become tied to their platform instead of people having the same capability at a language standard level. What do you think ? Why Sun and Microsoft consider developers too immature to just make the choice themselves ?

    Read the article

  • how can I get around no arrays as class constants in php?

    - by user151841
    I have a class with a static method. There is an array to check that a string argument passed is a member of a set. But, with the static method, I can't reference the class property in an uninstantiated class, nor can I have an array as a class constant. I suppose I could hard code the array in the static method, but then if I need to change it, I'd have to remember to change it in two places. I'd like to avoid this.

    Read the article

< Previous Page | 46 47 48 49 50 51 52 53 54 55 56 57  | Next Page >