bridge interview questions
Top bridge frequently asked interview questions
I was looking at the Proxy Pattern, and to me it seems an awful lot like the Decorator, Adapter, and Bridge patterns. Am I misunderstanding something? What's the difference? Why would I use the Proxy pattern versus the others? How have you used them in the past in real world projects?
Source: (StackOverflow)
What is the difference between the Bridge and Adapter patterns? Where i can use each pattern?
Source: (StackOverflow)
Am I correctly undestand Bridge Pattern:
BEFORE:
public class Main2 {
@SuppressWarnings("unused")
public static void main(String[] args) {
Car car11 = new BadNativeCar();
Car car12 = new GoodNativeCar();
Car car21 = new BadForeignCar();
Car car22 = new GoodForeignCar();
}
}
interface Car{
public void drive();
public void stop();
}
class NativeCar implements Car{
@Override
public void drive() {
}
@Override
public void stop() {
}
}
class ForeignCar implements Car{
@Override
public void drive() {
}
@Override
public void stop() {
}
}
class GoodNativeCar extends NativeCar{
}
class BadNativeCar extends NativeCar{
}
class GoodForeignCar extends ForeignCar{
}
class BadForeignCar extends ForeignCar{
}
AFTER(BRIDGE):
public class Main2 {
public static void main(String[] args) {
BadCar badCar = new BadCar();
GoodCar goodCar = new GoodCar();
CarAbstraction car11 = new NativeCar(badCar);
CarAbstraction car12 = new NativeCar(goodCar);
CarAbstraction car21 = new ForeignCar(badCar);
CarAbstraction car22 = new ForeignCar(goodCar);
}
}
interface CarAbstraction{
public void drive();
public void stop();
}
//Abstraction
abstract class CarAbstractionImpl implements CarAbstraction{
private CarImplementor carImplementor;
public CarAbstractionImpl(CarImplementor carImplementor) {
this.carImplementor = carImplementor;
}
@Override
public void drive() {
carImplementor.drive();
}
@Override
public void stop() {
carImplementor.stop();
}
}
//RefinedAbstraction1
class NativeCar extends CarAbstractionImpl{
public NativeCar(CarImplementor carImplementor) {
super(carImplementor);
}
}
//RefinedAbstraction2
class ForeignCar extends CarAbstractionImpl{
public ForeignCar(CarImplementor carImplementor) {
super(carImplementor);
}
}
//Implementor
interface CarImplementor extends CarAbstraction{
}
//ConcreteImplementor1
class GoodCar implements CarImplementor{
@Override
public void drive() {
}
@Override
public void stop() {
}
}
//ConcreteImplementor2
class BadCar implements CarImplementor{
@Override
public void drive() {
}
@Override
public void stop() {
}
}
Source: (StackOverflow)
Has anyone ever used the Bridge Pattern in a real world application? If so, how did you use it? Is it me, or is it just the Adaptor Pattern with a little dependancy injection thrown into the mix? Does it really deserve its own pattern?
Source: (StackOverflow)
I tried to read many articles on dofactory, wikipedia and many sites.
I have no idea on differences between bridge pattern and the strategy pattern.
I know both of them decouple an abstraction from its implementation and can change implementation at run time.
But I still don't know in which situation I should use strategy or in which situation I should use bridge.
Thanks in advance
Source: (StackOverflow)
I have a problem on deploying an EAR project to Wildfly 8 beta1. The project uses Hibernate Search 4.5 Alpha 1. There are indexed some entities. The project builds fine but when it is deployed an exception is thrown: Unable to guess FieldBridge for id in java.lang.Byte. I try to disable all hibernate search annotations but the exception still appear. Seams to be a bug. Any suggestions?
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:169) [wildfly-jpa-8.0.0.Beta1.jar:8.0.0.Beta1]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.0.0.Beta1.jar:8.0.0.Beta1]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_25]
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:463) [wildfly-security-manager-1.0.0.Beta3.jar:1.0.0.Beta3]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:178) [wildfly-jpa-8.0.0.Beta1.jar:8.0.0.Beta1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_25]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_25]
at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final.jar:2.1.1.Final]
Caused by: org.hibernate.search.SearchException: HSEARCH000135: Unable to guess FieldBridge for id in java.lang.Byte
at org.hibernate.search.bridge.impl.BridgeFactory.guessType(BridgeFactory.java:432)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.checkDocumentId(AnnotationMetadataProvider.java:159)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeMemberLevelAnnotations(AnnotationMetadataProvider.java:625)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeClass(AnnotationMetadataProvider.java:324)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor(AnnotationMetadataProvider.java:118)
at org.hibernate.search.engine.spi.AbstractDocumentBuilder.<init>(AbstractDocumentBuilder.java:100)
at org.hibernate.search.engine.spi.DocumentBuilderContainedEntity.<init>(DocumentBuilderContainedEntity.java:62)
at org.hibernate.search.spi.SearchFactoryBuilder.initDocumentBuilders(SearchFactoryBuilder.java:342)
at org.hibernate.search.spi.SearchFactoryBuilder.buildNewSearchFactory(SearchFactoryBuilder.java:217)
at org.hibernate.search.spi.SearchFactoryBuilder.buildSearchFactory(SearchFactoryBuilder.java:141)
at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:74)
at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:52)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:581)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1837)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:854)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:847)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:396)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:846)
at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:151) [wildfly-jpa-8.0.0.Beta1.jar:8.0.0.Beta1]
... 8 more
This is an example of entity that reproduces the exception:
@Entity
@Table(name = "flow")
public class Flow implements java.io.Serializable {
private static final long serialVersionUID = 3556704047257784867L;
private Byte id;
private String name;
private String description;
public Flow() {
}
public Flow(String name) {
this.name = name;
}
public Flow(String name, String description) {
this.name = name;
this.description = description;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Byte getId() {
return this.id;
}
public void setId(Byte id) {
this.id = id;
}
@Column(name = "name", nullable = false, length = 60)
@NotNull
@Length(max = 60)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "description", length = 400)
@Length(max = 400)
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
}
If the id is changed from Byte to Short is working fine. There is no builtin bridge for Byte. Maybe this is related, but the main problem is why hibernate search is looking for bridge if I don't have hibernate search annotations?
Source: (StackOverflow)
I want to create a broker to broker connection between ActiveMQ and WebSphere MQ in an embedded broker. I know that exists the network connector in activemq to do that (broker-to-broker), but I don't know how to configure it to connect to WebSphere MQ. Doing a search in the web I found some different ways to do with XML configuration and I noticed that the XML tags used does not refer the network connector, but refers a <jmsBridgeConnectors>
, so I do a research about this bridge connector by using java code but I wasn't able to find something that points me about how to do that.
Is there an explicit way to configure a bridge connector in ActiveMQ to a WebSphere MQ, for an embedded broker by using java code instead to use the XML configuration?
I know that is possible by using XML configuration, but, what if I am implementing an embedded broker (as I've mentioned before), and I want to configure the broker instance with a bridge connector to WebSphere MQ with java code, Does ActiveMQ provide a Class or Interface on the API to do this?
This is what I have done to connect two activemq brokers
try {
getBroker().addConnector("tcp://localhost:61616");
getBroker().addNetworkConnector("static:(tcp://remotBroker:61616)");
} catch (Exception e) {
logger.error("Unexpected ERROR, connection lost.");
e.printStackTrace();
}
One TransportConnector to listen in port 61616 and one Network connector to establish connection from my local broker to the remoteBroker, both brokers are
instances of activemq. Now I want a connection from my ActiveMQ local broker to WebSphere MQ broker using java code, no XML.
Source: (StackOverflow)
I'm reading some books about Design Patterns and while some describe the relation between the abstraction and the implementation as a composition, some describe it as an aggregation. Now I wonder: is this dependant on the implementation? On the language? Or context?
Source: (StackOverflow)
Is there a Python framework that makes it easy to build a bridge to any API?
A "bridge" in this context meaning simply: Some website or service exposes a JSON API. I want to get well-defined Python objects from the API instead of JSON.
It seems to me that the "bridge" pattern consists of some pretty simple components:
request / authentication handling
model definitions that match the API endpoints
translation from JSON into models
Rather than re-creating this pattern from scratch for every API that I want to make a bridge to, it seems like it would be smart to just have a generic "bridge" framework that simply required model definitions and some customization for the API you wanted to use. Sort of like Django, but for building bridge libraries instead of web apps.
Anybody know of anything like that out there?
Source: (StackOverflow)
It is said in Design Patterns - Elements of Reusable Object-Oriented Software book :
In situations where there's only one implementation (one-to-one) ,creating an
abstract implementor class isn't necessary.This is a degenerate case
of the bridge pattern; there's a one-to-one relationship between
Abstraction and Implementor.Nevertheless,this seperation is still
useful when a change in the implementation of a class must not affect
its existing clients- that is they shouldn't have to be
recompiled,just relinked.
I doubt about the benefit of compile time because I can't imagine a case in Java where a change in implementation makes recompile its superclass (abstract in this case).
For example, if we have X extends Y and a client do :
Y y = new X();
A change in X does not mean a recompilation of Y (of course if we don't want to change the method signatures of X)
It is exactly the same thing when using Bridge Pattern :
YAbstraction yabstraction = new YRefinedAbstraction(new XImplementor());
A change in XImplementor does not mean a recompilation of YAbstraction.
So, according to me, this benefit does not take place in Java and for a one-to-one => no Bridge Pattern needed.
Perhaps a change in a subclass force superclass to be recompiled in other languages ? like SmallTalk and C++ ?
What are your opinions ?
Source: (StackOverflow)
i have 2 containers by docker, and bridge like this:
root@venus-166:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ef99087167cb images.docker.sae.sina.com.cn/ubuntu:latest /bin/bash -c /home/c 2 days ago Up 21 minutes 0.0.0.0:49240->22223/tcp night_leve3
c8a7b18ec20d images.docker.sae.sina.com.cn/ubuntu:latest /bin/bash -c /home/c 2 days ago Up 54 minutes 0.0.0.0:49239->22223/tcp night_leve2
bridge name bridge id STP enabled interfaces
docker0 8000.72b675c52895 no vethRQOy1I
vethjKYWka
How can i get which container match veth*
?
ef99 => vethRQOy1I or ef99 => vethjKYWka
//----------------------------------------------------------
I know it works by ethtool
, but is there any better way?
Source: (StackOverflow)
I was trying to solve a problem which basically reduces to this:
Give a set of N nodes numbered from 1 to N and M edges where N<10000 and M<100000,
Find an Edge(u,v) which when added to the graph -- Minimizes the number of bridges in the graph.
If there are many such edges - Print the one which has lowest lexicographical value.
What would be an efficient approach to this problem?
Source: (StackOverflow)
We're trying to find out how I can use the Qt code we wrote in a gtk-based application. Rumour has it that adapters are possible, in less than 600 LoC, but apparently all links lead to web pages covered in 6 years worth of dust.
So here's the question: how can I create a QCoreApplication
that uses the gtk main loop?
Source: (StackOverflow)
When I create my container, I want to set a specific container's IP address in the same LAN.
Is that possible?
If not, after the creation can I edit the DHCP IP address?
Source: (StackOverflow)
Can anybody elaborate the Bridge design pattern and the Decorator pattern for me. I found it similar in some way. I don't know how to distinguish it?
My understanding is that in Bridge, it separate the implementation from the interface, generally you can only apply one implementation. Decorator is kind of wrapper, you can wrap as many as you can.
For example,
Bridge pattern
class Cellphone {
private:
Impl* m_OS; // a cellphone can have different OS
}
Decorator pattern
class Shirt {
private:
Person * m_p; //put a shirt on the person;
}
Source: (StackOverflow)