Questions tagged as 'classes-abstratas'

5
answers

What is and what is an abstract class for?

In object orientation, what is the meaning of an abstract class? What is its purpose?     
asked by 17.09.2015 / 15:07
2
answers

When should I use Inheritance, Abstract Class, Interface or a Trait?

Since PHP 5.4 we have Trait , which "are mechanisms that help (and much) reuse code, and serve perfectly to solve the problem of lack of multiple inheritance." Example of Abastrata Class abstract class AbstractUser { abstract publ...
asked by 08.07.2015 / 18:07
6
answers

Using many interfaces is a bad programming practice?

I'm a student in Information Systems and I'm modeling a game, a virtual pet that has its needs and talks with its owner, below follows the modeling of classes and interfaces. I showed it to a friend in Computer Science, he thought it had a lo...
asked by 09.07.2014 / 16:23
5
answers

Abstract Class X Interface

What is the difference between an abstract class and an interface? I do not understand when I should use one or the other.     
asked by 31.01.2014 / 19:08
4
answers

Is it possible to create an 'abstract class' in Javascript?

When creating a Javascript class whose attributes and methods are all static (for example, for storing predefined settings for a game), I would like to know if it is possible to define the class as abstract in a similar way as it can be (where t...
asked by 14.01.2014 / 02:05
1
answer

Java Interface 8

Java 8 allows you to implement methods in the interface itself. So I would like to know what an abstract class can do that an interface can not. Source: link     
asked by 01.10.2015 / 22:25
3
answers

Interface or Abstract?

I've read a lot of content on this topic until I get to this example: public interface Funcionario{ public void trabalha(); public void recebe(double salario); } public abstract class Geek implements Funcionario{...
asked by 08.10.2014 / 21:27
1
answer

The correct would be to leave the attributes of the abstract class as private or protected?

I do not know how I should leave those attributes.     
asked by 13.02.2016 / 18:24
1
answer

___ ___ erkimt I extend an abstract class or concrete? ______ qstntxt ___

When I need to extend a class, following the concept of Object Orientation, should I extend my code from an abstract or non-abstract class? What is the best practice to join?

    
______ azszpr89237 ___

There is no better option, you extend the class you need to extend. Whether it is abstract or not, it makes no difference to its code other than the fact that an abstract will possibly have unimplemented methods and its new class will have the obligation to create an implementation for all abstract methods contained in the class. optional).

If you want to know if it's better to create an abstract class or not, then it depends on what you want. An abstract class can not be instantiated. It is designed to be used as a template for other classes. Non-abstract can be used as models but can also be instantiated directly. You just make it an abstract class if you want to ban its instantiation (which is bound, if it is incomplete).

Of course, if the class has methods without implementation, they act as contracts for the derived classes to follow, that is, they function as if it were an interface, then the class must necessarily be abstract. Unable to instantiate classes with methods without implementation.

For example. If you have a class %code% and the derivatives of it %code% and %code% . Probably you do not need and maybe can not instantiate only the %code% . It is probably incomplete. You just created it to support the two (who knows other) derivatives I mentioned. It is almost an interface, but probably has variables and some methods with implementation. So %code% should probably be abstract.

Remembering that you can only inherit from a class. Abstract or not. Interface can several.

    
___

When I need to extend a class, following the concept of Object Orientation, should I extend my code from an abstract or non-abstract class? What is the best practice to join?     
asked by 27.09.2015 / 00:44
4
answers

Doubt about exercise with abstract class in Java

I would like to ask for your help again in this exercise. This time using the abstract class.    Create an abstract class FuncionarioAbstract with the String name attribute and the abstract method: public double getSalario();...
asked by 17.11.2016 / 14:58