Menu
  • HOME
  • TAGS

Interfaces in UML component diagram

Tag: oop,uml

In the UML class diagram the interface is equivalent to the interface concept in programming languages (a set of methods that the class that implement the interface should implement). I want to know if the interface in the component diagram has the same meaning. Are the interfaces mentioned in the component diagram the same interfaces that are detailed in the class diagram or should I treat every method in the component diagram as a separate interface?

Best How To :

There is actually no real difference between both. You can realize an interface with a class as well as with a component. Also you can show the realization in both cases with the socket/lollipop notation.

Components are not much different to classes. You can think of a component as a container that hosts a number of different classes. And if one of those classes realizes an interface you can expose that through the component (if you so wish). Additionally a component can have a lot of internal interfaces for its hosted classes.

Python class design: explicit keyword arguments vs. **kwargs vs. @property

python,class,oop

Without really knowing the particulars of your situation, the classic answer is this: if your class initializer requires a whole bunch of arguments, then it is probably doing too much, and it should be factored into several classes. Take a Car class defined as such: class Car: def __init__(self, tire_size,...

Serial modification of objects in R

r,oop

I would create a list of all your matrices using mget and ls (and some regex expression according to the names of your matrices) and then modify them all at once using lapply and colnames<- and rownames<- replacement functions. Something among these lines l <- mget(ls(patter = "m\\d+.m")) lapply(l, function(x)...

Calling a method on array iteration, from an object - PHP

php,arrays,oop

How about this <?php class MyClass { public $myArray=array(); public $htm = NULL; public function __construct(&$format=NULL) { //.. //Mysql query as $stmt //.. $this->myArray=$stmt->fetchAll(PDO::FETCH_ASSOC); $i=0; foreach($this->myArray as $row) { switch ($format) { case 'Page1' : $this->htm .= $this->format1($row); break; case 'Page2' : $this->htm .= $this->format2($row); break; default: $this->htm .= $this->format_default($row);...

Java Design Issue: Enforce method call sequence

java,oop,design-patterns

We commonly use StopWatch from Apache Commons StopWatch check the pattern how they've provided. IllegalStateException is thrown when the stop watch state is wrong. public void stop() Stop the stopwatch. This method ends a new timing session, allowing the time to be retrieved. Throws: IllegalStateException - if the StopWatch is...

Class fields as method parameters

oop,groovy

Assuming your EntityQuery.groovy ( model )looks like : private String typeName private Order order Assuming you have Order.groovy ( model ) that looks like : private String fieldName; private String orderType; private String orderName; use these model chain as a parameter, I think that is still strongly-typed (correct me). Your...

Rails modeling headache

ruby-on-rails,oop,models

It depends on whether you have many fields specific to agenda (not to month). If you do, it's better to have one separate model for agenda. BTW, It seems user and agenda are many-to-many relationship. In this case, you need one intermediate model between user and agenda. ...

Why metaclass's __call__ method called on class, but native class's __call__ not?

python,oop,metaclass

When you create a class instance, the metaclass's (whose instance the class is) __call__ is called. # Instantiate class. StandardClass() # StandardClass.__call__ is not called! When you create a class instance and then "call" the instance, then the class's __call__ is called. I don't think decorating __call__ with classmethod will...

Why can't I call a method I define in a field? [duplicate]

java,oop,methods

lorem is a method of an anonymous sub-class of B. Therefore you can't call it by using a reference of class B, and since it's anonymous, you can't cast b to a type that contains lorem.

program that creates one main object and creates a pet for each of them [closed]

swift,oop

Here is an example of a swift program that deals with pets. I found it on here. It has a protocol Animal that defines parts to an animal, with int legs, and boolean domesticated. protocol Animal { var legs: Int { get set } var domesticated: Bool { get }...

Why there isn't library of design patterns?

java,oop,design-patterns

Design patterns are solutions to programming problems that automatically implement good design techniques. Someone has already faced the issues you’re facing, solved them, and is willing to show you what the best techniques are. Answer to your question is - Design patterns are higher level than libraries. Design patterns tell...

Object Oriented Python - rectangle using classes and functions

python,function,class,oop,methods

Not sure I got your question right, but you may want to try: def getStats(self): return "width: %s\nheight: %s\narea: %s\nperimeter: %s" % (self.width, self.height, self.area(), self.perimeter()) To satisfy requirements 4 and 6, I would suggest something like: class Shape(object): def area(self): raise NotImplementedError def perimeter(self): raise NotImplementedError class Rectangle(Shape): def...

How to represent database columns and instance variables in UML

ruby-on-rails,ruby,uml,enterprise-architect

You can assign a stereotype to the database column like <<column>>. That will clearly differentiate between columns and instance variable. In EA you can create properties for a couple of languages, but not for Ruby. What EA does in those cases is to create <property get> and <property set> stereotyped...

Fatal error: Using $this when not in object context in E:\xampp\htdocs\

php,oop

$role = userrole::get_premium_subscritpion(1); I notice that you are trying to call a non-static function in a static way You may either change the function to static or change the way you call this function public static function get_premium_subscritpion { or $obj = new userrole(); $role = $obj->get_premium_subscritpion(1); ...

Can i use only _ (underscore) for the name of the class?

php,oop

Yes, you can use only underscore for the class name. class _{ function __construct(){ echo 'It works!'; } } new _(); Output: It works! DEMO...

Does Facebook use-case have one or more actors?

uml,use-case

An Actor by definition is external to the system under consideration. Therefore if you are writing use cases for the system Facebook then Facebook itself cannot be an Actor....

Laravel5: Access public variable in another class

php,class,oop,laravel,laravel-5

That's simple php stuff. Set the attribute as static and access it with ::. class LanguageMiddleware { public static $languages = ['en','es','fr','de','pt','pl','zh','ja']; } @foreach (App\Http\Middleware\LanguageMiddleware::$languages as $lang) ... @endforeach You should not have that in a middleware though. You'd better add a configuration (i.e in /config/app.php) with that array, and...

Python 2.7 @property usage results in error “global name '_c__pro' is not defined”

python,python-2.7,oop,properties,encapsulation

You need to use self. when accessing member variables: def __init__(self): self.__pro = 1 @property def pro(self): return self.__pro *10 ...

Add key and value (as argument via function) to array

php,oop,associative-array

Modify your addError function: public function addError($error, $key=false){ if($key){ self::$_errors[$key] = $error; }else{ self::$_errors[] = $error; } } Then it will go like this: if(strlen($value) < $rule_value){ $this->addError("More than {$rule_value} characters are needed as {$item}.", 'min_notmet'); } If you don't provide $key parameter, it will just add the element as...

creating multiple objects with browserify

javascript,oop,browserify

With CommonJS (Browserify), what you export will be what you get when you call require (however, be careful with assuming what you export is a singleton, it's not always the case from my experience). So in this case, you want to export the Human class directly. Then in each file...

How to extract variable from one function into another in same class in php

php,oop,abstract-class

<?php abstract class abc { protected $te; } class test extends abc { public function __construct() { $this->te = 5; } public function team() { $this->te += 100; } public function tee() { return $this->te; } } $obj = new test(); $obj->team(); echo $obj->tee(); -- edit: to make at least...

Downcasting doesn't work and functions called from object own class instead of where the function is (Java)

java,class,oop,methods,casting

When using inheritance within classes, overriding a method will ALWAYS call the child method regardless of casting. You can never change the type of an object, so a RockMusician - although it is an extension of Musician - is still a RockMusician and will be called by its type, not...

What is this thing called in Java?

java,oop,object,inheritance,immutability

They are called enumarations. You can find detailed info here they are defined as: public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } and used as: public class EnumTest { Day day; public EnumTest(Day day) { this.day = day; } public void tellItLikeItIs() { switch (day) {...

How to get the name of child class from base class when an object of child class is created

php,oop

You can use get_class() passing it the current object reference, like so: class Base_class { function __construct() { $calledClassName = get_class($this); } } Edit: You can find more info on get_class() in the PHP manual http://php.net/manual/en/function.get-class.php...

How to check if objectB used instance of objectA from objectA using private variables

php,oop

Use Getters and Setters. The below code will let the $mesh_name property be read, but not written by external code. class MyObject { protected $mesh_name = 'foo'; protected $accessible = ['mesh_name']; protected $writable = []; public function __get($name) { if( in_array($name, $this->accessible) ) [ return $this->name; } else { //...

Javascript: Access function within deep object on parse

javascript,oop,object

Because scope in which function2 is defined does not contain definition of object1. Then when you try to access object1.object2 it throws error because object1 is not defined

“Undefined method PDO::execute()” despite using prepare

php,oop,pdo,undefined

Create a variable to store your prepared statement then execute that. $connection = MYSQLDatabase::getInstance()->getConnection(); $statement = $connection->prepare("INSERT INTO users etc etc......."); $insertArray = $statement->execute(array( ":username" => $_POST["username"] )); ...

Python: I'm getting an error when using self.name

python,oop,self

You are trying to print print witch.enemy_name But the attribute is self.name = enemy_name So you should be calling print witch.name ...

Interface for Child Class that Inherits from parent class without reimplementing parent class

c#,oop,inheritance,interface

If I understand you correctly, you're saying that you want an inheritance hierarchy in your interfaces as well as your classes. This is how you'd achieve such a thing: public interface IBase { // Defines members for the base implementations } public interface IDerived : IBase { // Implementors will...

Extending a method in PHP

php,oop

You dont need to add two function to do same work all you need to do is pass parameter to function public function getResultsByID($userID = null,$flag){ $sqlParams = array(); if (!$userID) { throw new Exception("No User ID Provided"); } $sqlParams['userID'] = $userID; if($flag=value1){ $sql = "SELECT t.user_id,t.owner_id,t.store_id FROM users t...

Loop by Object inside another Object in Java

java,list,oop,collections

This will solve the problem, seasonMap contains values in the order you need (assuming classes implement Comparable) Map<Season, Map<Building, List<Info>>> seasonMap = new TreeMap<>(); for (Building building : buildings) { for (Map.Entry<Season, List<Info>> e : building.infosBySeason.entrySet()) { Season season = e.getKey(); List<Info> infos = e.getValue(); if (!seasonMap.containsKey(season)) { seasonMap.put(season, new...

C# Code design / Seperate classes for each TabControl

c#,oop,architecture,software-design,code-design

Place a UserControl on each tab.

how to make a note with implementation in a UML class-diagram in visual paradigm

uml,visual-paradigm

I have no idea how or whether this is possible with VP (I know for sure that you can't do it with Enterprise Architect which is pretty much UML2.x compliant). But you could hook the link near the position in the appropriate compartment (EA also has a feature to lock...

JavaScript Functional Classes [closed]

javascript,oop

Answer: None of the above. Try something like this: function Car(loc) { this.loc = loc; } Car.prototype.move = function () { this.loc++; }; var obj = new Car(someLoc); obj.move(); This uses object prototyping which is JavaScript's implementation of object-oriented programming. You can read more about prototypes and inheritance here on...

Call to a member function query() on a non-object in PHP when trying to access parent constructor in php

php,mysql,oop

You're doing it wrong First thing is that PHP4-style constructors are deprecated, use __construct method to define a costructor. Second is that you must not return from constructor but rather keep the connection object inside class as instance property. Third is that you must call parent methods using parent keyword....

Making list of objects of class with function overloading

c++,oop

I think the problem is in this line: currentNodePtr->data = &new_car; of the function void StringOfCar::push(Car & new_car). That should be currentNodePtr->data = currentCarPtr; ...

Is dynamic_casting through inheritance hierarchy bad practice?

c++,oop,inheritance,casting

There are a lot of questions on dynamic_cast here on SO. I read only a few and also don't use that method often in my own code, so my answer reflects my opinion on this subject rather than my experience. Watch out. (1.) Why is casting up/down considered bad design,...

Passing variable data between classes OO Javascript

javascript,oop

Maybe can put contactsAppModel.init(); on the first line of your contactsApp.init() method.

Python method that can be called on a list of objects

python,oop,syntax

The only way to do exactly what you're asking for is to subclass python build-in class list. This should help....

How access member function from arrayobject in a loop

c++,oop

Use array_object[i]->get_data(); instead of array_object[i].get_data();. The DOT(.) operator is used when an object try to access its class member functions/variables whereas Arrow(->) operator is used if the object is a pointer. Now, you declared Matrix *array_object[100]; Which means array_object is an array of Matrix pointers. Hence you need to use...

Calling an object and its method from another object class method

javascript,class,oop,object,methods

Welcome to the world of javascript where you are not using it to just paint and moves boxes :) Coming to your question: //Initialize objects var spaceButton = new Navigation('#spaceWarp'); var stars1 = new Stars('#stars1'); var stars2 = new Stars('#stars2'); var stars3 = new Stars('#stars3'); The initialization of your objects...

Why does the “this” keyword refer to the subclass too?

java,oop,this

Generally speaking, since this refers to the current instance, how is it possible that Fireball.onChat(PlayerChatEvent) is registered too? Because when you're constructing an instance of Fireball, this refers to the Fireball being constructed at execution time. The compile-time type of this is Spell, but if you print out this.getClass()...

PHP Data Objetcs (PDO) example

php,mysql,oop,pdo

It looks alright for a basic implementation, beside that you shouldn't echo something inside a class. If you want see a well implemented solution, have a look into eloquent created by taylor otwell. That should give you heaps of ideas how to improve your code. https://github.com/laravel/framework/blob/4.2/src/Illuminate/Database/Connection.php...

Why has java kept length field in the jvm public

java,oop

A bigger question is; why is there no class file for int[]? Without such a class file there is no where to put such a method, so it is purely a language feature. It looks like a field of int[] but it not. They could have made it look like...

My simple php class not working [closed]

php,class,oop

You can't use type hints with scalar values ( in you case string - check the docs) Change your constructor in this way: public function __construct($scheme, $hostname, $www) { $this->scheme = $scheme; $this->hostname = $hostname; $this->www = $www; } and it should work...

PHP mysqli_fetch_array() OOP style

php,oop,mysqli

You're doing two conflicting things $con= new mysqli('localhost','root','','afiliate'); $query="SELECT * FROM product WHERE ID=? "; $stmt->bind_param("i",$ID); /* $ID has a value, it's ok */ $stmt->execute(); So at this point $stmt is a mysql_stmt object. If you have mysqlnd installed you can do this $result = $stmt->get_result(); while($row=$result->fetch_row()){ echo $row['name']; }...

Where is the defination of rails validators?

oop,ruby-on-rails-4

These are Rails methods: You can find valid? here and its code on Github. Likewise with new_record?, you can find a description and its source code here. Also, here is a link to the Rails repository on Github. These methods are not defined in the project, they are defined in...

Function pointer to singleton class instance function

c++,oop,pointers,singleton

Simply create a normal class without static methods, ditch the singleton pattern aside, and create an instance. The burden of singleton pattern usually outweigh any benefit....

How to implement repeated behavior when inheritance isn't an option

java,oop,interface

Your solution is perfectly valid for Java. You are actually using the design pattern Use Composition Over Inheritance. As @Naruto_Biju_Mode says in a comment, if you are using Java 8, you can move the implementation to a default method of Transformable however you would have to make the helper class...

Check if object has given properties

php,oop

You can use at least three ways to do it: property_exists() isset() ReflectionClass::hasProperty() All of these are demonstrated below: <?php class myClass { public $a=1; public $b=2; public $c=3; } $myObj = new myClass(); $reflectionClass = new ReflectionClass($myObj); foreach (['a', 'b', 'c', 'd'] as $property) { printf("Checking if %s exists:...

Calling an add on a list from a getter of an object does not work as expected

java,oop

Your posted sample code has syntax errors. Fix those and the code does what you're wanting. public class Customers { private List<String> names; public Customers(List<String> names) { this.names = names; } public List<String> getNames() { return names; } @Override public String toString() { StringBuilder sb = new StringBuilder(); for (String...