简体   繁体   English

将网页表示为类

[英]represent webpage as a class

I was asked a question few days back and I am still not sure what is the proper answer to this question. 几天前有人问我一个问题,但我仍然不确定该问题的正确答案是什么。 I think I can create a class webpage and the members of the class can be HTML tags and there will be few methods which manipulate DOM elements. 我想我可以创建一个类网页,并且该类的成员可以是HTML标记,并且几乎没有操作DOM元素的方法。 I am not sure if this question is too general or vague. 我不确定这个问题是否太笼统或模糊。 Can you please provide your thoughts? 您能提供您的想法吗?

Note: This was asked in an interview for software developer. 注意:这是在采访中要求软件开发人员进行的。

Representing a real life object means to analyse its structure and create an abstract model for it. 表示现实生活中的对象意味着分析其结构并为其创建抽象模型。

A house for example is a rather complex object with doors, windows and levels and so on and to forth. 例如,房屋是一个相当复杂的物体,带有门,窗户和水平仪等等。 But is has an network infrastructure and water installation and many many things more. 但是拥有网络基础设施和供水设施还有许多其他东西。 You can start and identify the most important aspects of a house like doors and windows (or level). 您可以启动并确定房屋的最重要方面,例如门窗(或水平)。

A webpage is similar complex. 网页很复杂。 It has an URL, a header, and a body, language, encoding, a purpose, incoming links, outgoing links. 它具有URL,标头以及正文,语言,编码,目的,传入链接,传出链接。

Each of this items has their own specific aspects to describe them. 每个项目都有自己的特定方面来描述它们。 So in your case, the interview question is aiming for such an object oriented analysis. 因此,在您的情况下,面试问题旨在进行这种面向对象的分析。 There is no "right" answer to this but you can start with simple items: 对此没有“正确”的答案,但是您可以从简单的项目开始:

Webpage:
 - url, java.lang URL
 - title, String
 - body, String or DOM
 - head, new type Header
 - outgoing links, List<Webpage>
 - incoming links, List<URL>
 - type, enum (static, dynamic)

and so on. 等等。

You would have to model a Header now. 您现在必须建模标题。

This representation may have methods to manipulate the contents. 该表示可以具有操纵内容的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM