Java ~ Class, abstract class and interface, java Abstract class Interface

Source: Internet
Author: User

Java ~ Class, abstract class and interface, java Abstract class Interface

Recently, I was fascinated by the world of java, hoping to refactor my lind to a java version. Although I encountered some minor problems, I also solved them,Knowledge needs to be accumulated, and programmers need a pursuit!

Similar to C #, this class only removes the attribute concept and uses methods to operate specified fields.

package lind.Test;public class User extends Entity {    public User(int id, String name) {        super(1);        this.name = name;    }    private String name;    /**     * @return the name     */    public String getName() {        return name;    }    /**     * @param name     *            the name to set     */    public void setName(String name) {        this.name = name;    }}

Abstract classes are a set of types. Some methods and fields are exposed for use by subclasses.

Package lind. test;/*** Entity ** @ author Administrator **/public abstract class Entity {public Entity (int id) {this. setId (id);}/*** @ return the id */public int getId () {return Id ;} /*** @ param id * the id to set */public void setId (int id) {Id = id;} private int Id ;}

The three interfaces specify the actions of a group of operations, such as warehouse CURD operations. They may publicly add, delete, modify, query, and other methods.

Package lind. repository; import java. util. arrayList; import java. util. function. predicate; public interface IRepository <T> {/*** add ** @ param entity */void Insert (T entity ); /*** Update ** @ param entity */void Update (T entity);/*** Delete ** @ param entity */void Delete (T entity ); /*** return list ** @ return */ArrayList <Object> GetModel (Predicate <T> predicate); ArrayList <Object> GetModel ();}

The four generic classes and generic interfaces are not as flexible as Csharp. during use, you must note that, of course, they have the same meaning and are mainly used to abstract and replace a class of functions, during implementation, you can directly transfer the corresponding type. Generally, our warehousing objects, such as user warehousing, can inherit a generic warehousing class, as shown below:

Package lind. Test; // public class UserDao extends JdbcDaoSupport <User> {}

5. After a non-generic class inherits the generic class, the name of the generic class is output.

This is a small trick, mainly to get the type in the generic class. It should be noted that there must be a non-generic class to inherit it and instantiate it, this type can be parsed. This is indeed not comparable to Csharp.

 

Thank you for your patience. Next time we will introduce the Hash table!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.